Page 1 of 1

Can't figure out repeat with error code

Posted: Tue Feb 23, 2016 7:05 pm
by tedherr
I'm having trouble with my script not executing. It returns an error message:

error in 'with' start condition expression

for this code:

repeat with n = 1 to howMany

In this script:

on createDates
global oneDate
-- clear fields
put "" into field "The Dates"
put field "Quantity" into howMany
-- create random dates
repeat with n = 1 to howMany
do createOneDate
put oneDate into line n of field "The Dates"
end repeat
end createDates

It executed successfully about a dozen times, then started generating the error code. I tried retyping it, quitting and rebooting, but the error condition persists.

Any suggestions?

Re: Can't figure out repeat with error code

Posted: Tue Feb 23, 2016 7:24 pm
by jmburnod
Welcome to this forum,

And thanks for this post I can help (english LiveCoders are often faster than me) :D
I don't understand your "do createOneDate" line. Is there a createOneDate message ?

Try this:

Code: Select all

on createDates
   put "" into field "The Dates"
   put the value of field "Quantity" into howMany -- the value is safer when you need an integer
   repeat with n = 1 to howMany
      put createOneRandomDate() into line n of field "The Dates"
   end repeat
end createDates

function createOneRandomDate
   put the seconds into tSec
   put random(tSec) into tDateSec
   convert tDateSec to date
   return tDateSec
end createOneRandomDate
Best regards
Jean-Marc

Re: Can't figure out repeat with error code

Posted: Tue Feb 23, 2016 7:27 pm
by FourthWorld
Where is the value of createOneDate defined? And do you really need "do" there? What should it be doing?

Re: Can't figure out repeat with error code

Posted: Tue Feb 23, 2016 8:04 pm
by tedherr
Jean-Marc,

Thank you for your suggestions and your code. I've incorporated your code.

Your comment about using "the value of" in order to ensure that the quantity was an integer led me to the real issue: It turn out the Quantity field was holding a character string that couldn't be interpreted as a number. It was something akin to 30\n10 (\n as a line return).

Your help allowed me to fix the problem and move forward!
Thank you,
Ted

Re: Can't figure out repeat with error code

Posted: Tue Feb 23, 2016 8:13 pm
by jmburnod
Ted,
Glad to help
I forgot to precise I don't know yet how dates work before 1/1/70.
Jean-Marc

Re: Can't figure out repeat with error code

Posted: Tue Feb 23, 2016 9:36 pm
by FourthWorld
jmburnod wrote: I don't know yet how dates work before 1/1/70.
You don't. According to Unix (and subsequently Windows and Linux), time didn't exist before then. :)

Re: Can't figure out repeat with error code

Posted: Tue Feb 23, 2016 9:54 pm
by dunbarx
Hi.

You can use negative seconds:

Code: Select all

on mouseUp
   get -1696666622 --March 1916
   convert it to date
   answer it
end mouseUp

Re: Can't figure out repeat with error code

Posted: Tue Feb 23, 2016 10:02 pm
by jmburnod
Hi Craig,
Thanks fo the hint.
What about date before 0 ?
I tried :

Code: Select all

on mouseUp
   get -111696666622 -- ???
   convert it to date
   answer it --
end mouseUp
The result is -111696666622

Re: Can't figure out repeat with error code

Posted: Tue Feb 23, 2016 10:14 pm
by dunbarx
Jean Marc.

You have too much negative time on your hands.

I tried this with a button and a field:

Code: Select all

on mouseUp
   repeat with y = 1 to 325
   get -100000000 * y
   convert it to date
   put it into line y of temp
   end repeat
put temp into fld 1
end mouseUp
The dates seem valid back to about the year 1000 or so. I did not parse the centuries in the field output, though it would be fun (gasp!) to do so. The value "325" is the max this particular handler will go using increments of 100,000,000 seconds, or about 3 years. It would be a hoot to find the actual second where the process breaks down, and you get those useless strings of digits instead of a date.

Challenge, anyone?

Craig

EDIT.
See a new thread about this ("Big Bang"), which is off-topic from the OP.