Page 1 of 1

"Convert" command struggle

Posted: Tue Sep 30, 2008 5:44 pm
by Srdjan
Can you, please, explain why this works:

on mouseUp
convert "Thursday, February 17, 2000" to dateItems
answer item 1 of it
end mouseUp

And why this this doesn't work:

on mouseUp
put "Thursday, February 17, 2000" into tMyYear
convert tMyYear to dateItems
answer item 1 of it
end mouseUp

(rev studio 3.0)

I am totally confused :shock:

Thanks

Posted: Tue Sep 30, 2008 7:51 pm
by Janschenkel
Convert expects a variable or (if you use a literal as in the first example), Revolution assumes you're working with the 'it' local variable. The second should work if you use 'tMyYear' instead of it in your answer's expression:

Code: Select all

on mouseUp 
  put "Thursday, February 17, 2000" into tMyYear 
  convert tMyYear to dateItems 
  answer item 1 of tMyYear 
end mouseUp
Hope this helped,

Jan Schenkel.

Posted: Tue Sep 30, 2008 8:00 pm
by mwieder
Here's what's going on (this is somewhat nonintuitive):

In your second example you're placing a literal value into a variable. Then you're converting that variable in place into a dateItem list.

In the first example, by contrast, you're taking a literal value and converting it in midair. Since there's no named variable to work with, the rev engine is putting the value into the "it" variable and converting it there.

When you answer the value of "it" your first example returns what you expect. Your second example doesn't put anything into the "it" variable and so you see an empty string there. Maybe this will make it clearer:

on mouseUp
convert "Thursday, February 17, 2000" to dateItems
-- it now contains the dateItems list
answer item 1 of it
-- it now contains "OK" from the answer dialog
put "Thursday, February 17, 2000" into tMyYear
convert tMyYear to dateItems
-- it still contains "OK" from the answer dialog
-- but tMyYear has the list you're looking for
answer it
end mouseUp

Posted: Tue Sep 30, 2008 9:27 pm
by Srdjan
Thank you Jan and mwieder.
That was enlightening!