Re: conditional error
Re: conditional error
- Subject: Re: conditional error
- From: John W Baxter <email@hidden>
- Date: Sun, 22 Jul 2001 09:46:46 -0700
At 4:50 -0400 7/22/2001, monk wrote:
>
when i run this, the first 'if' compiles fine, but the second and third give
>
me an error that 'can't make some data into expected type'
>
--
>
>
if button returned of (display dialog "process by:" buttons {"word", "line",
>
"paragraph"} default button "word") is "word" then
>
>
set _listsource to (read _source as text using delimiter {return,
>
space})
>
>
else if button returned is "line" then
>
>
set _listsource to (read _source as text using delimiter {return})
>
>
else
>
>
set _listsource to (read _source as text using delimiter {space})
>
>
end if
>
>
--
>
>
any ideas on why this is failing?
Yes...display dialog returns a record, one item of which is named button
returned. Your if statement gets that, but then it has fallen onto the
floor. The button returned in the else if is meaningless.
I would likely do it this extra wordy way (usual line wrap warning):
set outcome to (display dialog "process by:" buttons {"word", "line",
"paragraph"} default button "word")
if button returned of outcome is "word" then
display dialog ("word")
--set _listsource to (read _source as text using delimiter {return, space})
else if button returned of outcome is "line" then
display dialog ("line")
--set _listsource to (read _source as text using delimiter {return})
else
display dialog ("paragraph")
--set _listsource to (read _source as text using delimiter {space})
end if
Although it could also be done like this:
set theButton to button returned of (display dialog "process by:" buttons
{"word", "line", "paragraph"} default button "word")
if theButton is "word" then
display dialog ("word")
--set _listsource to (read _source as text using delimiter {return, space})
else if theButton is "line" then
display dialog ("line")
--set _listsource to (read _source as text using delimiter {return})
else
display dialog ("paragraph")
--set _listsource to (read _source as text using delimiter {space})
end if
And many would use the built-in result variable, but I almost never do
(because I never know in advance that I'm not going to insert something
between the setting of result and the using of it which changes its
contents). It does work here:
display dialog "process by:" buttons {"word", "line", "paragraph"} default
button "word"
if button returned of the result is "word" then
display dialog ("word")
--set _listsource to (read _source as text using delimiter {return, space})
else if button returned of the result is "line" then
display dialog ("line")
--set _listsource to (read _source as text using delimiter {return})
else
display dialog ("paragraph")
--set _listsource to (read _source as text using delimiter {space})
end if
--John
--
John Baxter email@hidden Port Ludlow, WA, USA