Re: simple problem?
Re: simple problem?
- Subject: Re: simple problem?
- From: "Stockly, Ed" <email@hidden>
- Date: Mon, 19 Nov 2007 17:42:28 -0800
- Thread-topic: simple problem?
> Hi. I'm trying to write a very simple script and I can't get it to
> work. It seems as though my boolean expressions are not being
> evaluated properly.
What's happening in your script is a class mismatch.
The class of the result of the choose from list command is a list.
{"Group A"}, for example.
The display dialog command automatically coerces the list to string, but the
boolean comparison does not.
{"Group A"} does not equal "Group A" so your boolean never comes true.
In script editor, open the apple even log and add these two commands
commands to the end of your script and run it:
log group
log class of group
You'll see the what's happening.
Paul suggested coercing the list to string immediately, which works.
So would this:
Set group to group as string
If group = "Group A" then
You could also try this:
If "Group A" is in group then
HTH,
ES
> The idea is that the user picks a group from a list. Based on the
> group they choose, the three variables mode0, mode1 and mode2 are
> assigned. But it's not working. No matter which group the user
> chooses, the default 'else' is being executed and the variables are
> being assigned '-1'. I don't understand what's happening. I put in
> display dialogs all over the place to try to figure out what's going
> on. The first display dialog before the if statement works and tells
> me which group has been selected. But then it doesn't get into any of
> the if statement branches, except the default 'else'.
>
> Here is the script:
>
> set group to choose from list {"Group A", "Group B", "Group C",
> "Group D", "Group E", "Group F"} with prompt "Please select the group
> letter you have been assigned:"
> display dialog "You selected " & group & "."
> if group is "Group A" then
> display dialog "You chose group A."
> set mode0 to "0"
> set mode1 to "1"
> set mode2 to "2"
> else if group is "Group B" then
> display dialog "You chose group B."
> set mode0 to 0
> set mode1 to 2
> set mode2 to 1
> else if group is "Group C" then
> display dialog "You chose group C."
> set mode0 to 1
> set mode1 to 0
> set mode2 to 2
> else if group is "Group D" then
> display dialog "You chose group D."
> set mode0 to 1
> set mode1 to 2
> set mode2 to 0
> else if group is "Group E" then
> display dialog "You chose group E."
> set mode0 to 2
> set mode1 to 0
> set mode2 to 1
> else if group is "Group F" then
> display dialog "You chose group F."
> set mode0 to 2
> set mode1 to 1
> set mode2 to 0
> else
> set mode0 to -1
> set mode1 to -1
> set mode2 to -1
> end if
>
> display dialog "Mode0 is " & mode0 & ", and Mode1 is " & mode1 & ",
> and Mode2 is " & mode2
>
> Anyone have any ideas? I'm a proficient programmer, and I feel pretty
> dumb being stumped on an if statement. But I'm new to Applescript, so
> maybe it's something I'm just not aware of.
>
> Thanks!
>
> Celine
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden