Problem with text returned from dialog

–This is very similar to my previous post but easier to follow. Please copy this into a new script window and enter “ab” into the dialog box.

set CorrectEntrySet to {“ab”, “cd”}

set EntryDialogDisplay to display dialog “My Selection” buttons {“OK”} default button “OK” default answer “”
set EnteredLetters to text returned of EntryDialogDisplay

if EnteredLetters is in CorrectEntrySet then
beep
end if
get EnteredLetters

–Even if you enter “ab” or “cd” you will not get a beep, even though the result window shows EnteredLetters to be what you entered. However, if you change

–to
–<if “ab” is in CorrectEntrySet>
–of course you get a beep. But in the first case EnteredLetters was “ab”. I truly can`t figure this out. Please help me out.

–Bruce Whitred
–Follow Your Dreams
–P.S. This was compiled using AppleScript

You are running Panther, true?
You sample code works fine for me. However, I’ve found some problems with text returned from dialogs, and some stuff working in the past now throw errors.
I’m not sure, but I’d say that in versions previous, at least, to AS 1.9.3 text returned from dialogs was not Unicode text, but plain strings. Probably something related to the new changes to the “display dialog” command.

Try adding this line before the “if” block:

set EnteredLetters to «class ktxt» of (EnteredLetters as record)

Or, if you need Unicode data to play with:

set CorrectEntrySet to {"ab" as Unicode text, "cd" as Unicode text}

And let us know!

This works fine on my machine (Mac OS X 10.3.2, AS 1.9.3):

There is nothing in this code that should not work in any version of AS on any Mac OS. Perhaps you should reboot and try again.

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

The suggestion to put the following command

set EnteredLetters to «class ktxt» of (EnteredLetters as record)

before the “if” block worked. Thank you very much.

I am using Panther and as I`m running the Japanese OS version, maybe the unicode is figuring into the problem.

By the way, what does the <> stand for?

Anyway, thank you all again. You really helped me out.

Unicode data is a collection of ktxt and ksty. Try this:

"a" as Unicode text as record

If you see the result…
«class ktxt»:“a”
«class ksty»:«data styl0001000000000010000E00030000000C000000000000»
Where ktxt would be the “plain text”.

Actually, that code brings back this response for me:

{«class ktxt»:“a”, «class ksty»:«data styl0001000000000010000E40000000000C000000000000»}

What does that tell me?
Thanks again. :rolleyes:

I’m not a expert in Unicode stuff, but I think that “ktxt” is the “text” itself (two-byte) and “ksty” is the style information. You can see the only difference if we compare our ksty data is the “font-family id” (mine is “0003”, most probably “Geneva”; yours is “4000”, ?)
Traditionally, we use the “as record” trick to extract “plain text” (called “string” in AppleScript) from text with extra information (such as “International text” -contains script code and language-, “styled text” -contains style data, such as bolds and colors- or “Unicode text” -doublebyte text, plus style data).

Thanks for your help. I`m learning something new every day.