"Convert" doesn't work with variable holding seconds

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
oregon_tony
Posts: 3
Joined: Fri Jan 14, 2011 11:48 am

"Convert" doesn't work with variable holding seconds

Post by oregon_tony » Fri Jan 14, 2011 12:25 pm

if I do this:
-- =====================
convert "1294811623" to dateItems
convert it from dateItems to long date and long time
answer it
-- =====================
...It Works!. I get a nice properly formatted date like I would expect. BUT if I do this:

-- =======================
put "1294811623" into myVar
convert myVar to dateItems
convert it from dateItems to long date and long time
answer it
-- =======================

... the answer box comes back <empty>, or sometimes it returns the literal string "handled"

What gives?
Thanks,
Tony

oregon_tony
Posts: 3
Joined: Fri Jan 14, 2011 11:48 am

Re: "Convert" doesn't work with variable holding seconds

Post by oregon_tony » Fri Jan 14, 2011 12:45 pm

It looks like it is some type of casting bug with the value of the variable holding the seconds time stamp.

If I modify my code and do:

convert (myVar & "") to dateItems

....it works.
Appending a "" (empty string) onto the end of my numeric value of the original time stamp solves the problem.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: "Convert" doesn't work with variable holding seconds

Post by bn » Fri Jan 14, 2011 2:06 pm

Hi Tony,

welcome to the forum.
-- =======================
put "1294811623" into myVar
convert myVar to dateItems
convert it from dateItems to long date and long time
answer it
-- =======================
try

Code: Select all

on mouseUp
   put "1294811623" into myVar
   convert myVar to dateItems
   convert myVar from dateItems to long date and long time
   answer myVar
end mouseUp
this works

Please be careful with it. Whenever you use it put it into another variable right away. It changes when you least expect it.

Kind regards

Bernd

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: "Convert" doesn't work with variable holding seconds

Post by Klaus » Fri Jan 14, 2011 2:31 pm

Hi Tony,

Code: Select all

...
put "1294811623" into myVar
convert myVar to dateItems
## Here you use MYVAR
convert it from dateItems to long date and long time
answer it
## And here you use IT, which is apparently empty at that time, 
## so the result will also be empty!
...
Best

Klaus


EDIT:
Damn, Bernd was faster!
I really sould releoad the page after a 30 minute phone call :D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: "Convert" doesn't work with variable holding seconds

Post by dunbarx » Fri Jan 14, 2011 3:10 pm

Just my two cents.

"It" is a special reserved variable, that can change depending on what you are up to, and is the target variable of many functions. For example "get 7" puts a 7 into the variable "it". Answering an "ask" dialog puts the data into "it".

But "it" is almost too common a word not to become confusing to a beginner. You made a very english-like assumption that you can simply convert "it"..., as if "it" referred to the variable you loaded a line earlier.

Don't do it. Or, watch it.

oregon_tony
Posts: 3
Joined: Fri Jan 14, 2011 11:48 am

Re: "Convert" doesn't work with variable holding seconds

Post by oregon_tony » Fri Jan 14, 2011 8:51 pm

Thanks everyone for the detailed responses, I greatly appreciate it.
I'm new to RunRev, but I'm extremely impressed with the amount of work you can do with such a small amount of code.

Thanks again,
Tony

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: "Convert" doesn't work with variable holding seconds

Post by FourthWorld » Fri Jan 14, 2011 9:26 pm

oregon_tony wrote:I'm new to RunRev, but I'm extremely impressed with the amount of work you can do with such a small amount of code.
Some consider it verbose based on the number of tokens in each line, without noticing just how few lines there are. ;)
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: "Convert" doesn't work with variable holding seconds

Post by dunbarx » Fri Jan 14, 2011 10:35 pm

One thing that might still be unclear.

When you simply convert a number into another date/time format, the reformatted data is placed into the "it" variable, because no other existed at the time. This is just default behavior. A better way is to prepare your date first:

on mouseUp
put "1294811623" into temp
convert temp to dateItems
answer temp
end mouseUp

This never calls on "it" to come into play at all. As Bernd meant, the several processes that target this special variable can reload it without your knowing about it. Hence his advice to pull such information out into another explicit variable right away. "It" is very useful, and ubiquitous. But I always lock my data safely somewhere else as soon as I can. One line later in your code is a good place.

Craig Newman

Post Reply