"Convert" command struggle

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Srdjan
Posts: 26
Joined: Mon Aug 04, 2008 7:17 am

"Convert" command struggle

Post by Srdjan » Tue Sep 30, 2008 5:44 pm

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

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Tue Sep 30, 2008 7:51 pm

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.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Post by mwieder » Tue Sep 30, 2008 8:00 pm

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

Srdjan
Posts: 26
Joined: Mon Aug 04, 2008 7:17 am

Post by Srdjan » Tue Sep 30, 2008 9:27 pm

Thank you Jan and mwieder.
That was enlightening!

Post Reply