Page 1 of 1
"Convert" doesn't work with variable holding seconds
Posted: Fri Jan 14, 2011 12:25 pm
by oregon_tony
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
Re: "Convert" doesn't work with variable holding seconds
Posted: Fri Jan 14, 2011 12:45 pm
by oregon_tony
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.
Re: "Convert" doesn't work with variable holding seconds
Posted: Fri Jan 14, 2011 2:06 pm
by bn
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
Re: "Convert" doesn't work with variable holding seconds
Posted: Fri Jan 14, 2011 2:31 pm
by Klaus
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

Re: "Convert" doesn't work with variable holding seconds
Posted: Fri Jan 14, 2011 3:10 pm
by dunbarx
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.
Re: "Convert" doesn't work with variable holding seconds
Posted: Fri Jan 14, 2011 8:51 pm
by oregon_tony
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
Re: "Convert" doesn't work with variable holding seconds
Posted: Fri Jan 14, 2011 9:26 pm
by FourthWorld
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.

Re: "Convert" doesn't work with variable holding seconds
Posted: Fri Jan 14, 2011 10:35 pm
by dunbarx
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