Can't figure out repeat with error code

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
tedherr
Posts: 2
Joined: Tue Dec 05, 2006 6:05 am

Can't figure out repeat with error code

Post by tedherr » Tue Feb 23, 2016 7:05 pm

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?

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Can't figure out repeat with error code

Post by jmburnod » Tue Feb 23, 2016 7:24 pm

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
https://alternatic.ch

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

Re: Can't figure out repeat with error code

Post by FourthWorld » Tue Feb 23, 2016 7:27 pm

Where is the value of createOneDate defined? And do you really need "do" there? What should it be doing?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

tedherr
Posts: 2
Joined: Tue Dec 05, 2006 6:05 am

Re: Can't figure out repeat with error code

Post by tedherr » Tue Feb 23, 2016 8:04 pm

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Can't figure out repeat with error code

Post by jmburnod » Tue Feb 23, 2016 8:13 pm

Ted,
Glad to help
I forgot to precise I don't know yet how dates work before 1/1/70.
Jean-Marc
https://alternatic.ch

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

Re: Can't figure out repeat with error code

Post by FourthWorld » Tue Feb 23, 2016 9:36 pm

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. :)
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: 10352
Joined: Wed May 06, 2009 2:28 pm

Re: Can't figure out repeat with error code

Post by dunbarx » Tue Feb 23, 2016 9:54 pm

Hi.

You can use negative seconds:

Code: Select all

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Can't figure out repeat with error code

Post by jmburnod » Tue Feb 23, 2016 10:02 pm

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
https://alternatic.ch

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

Re: Can't figure out repeat with error code

Post by dunbarx » Tue Feb 23, 2016 10:14 pm

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.
Last edited by dunbarx on Tue Feb 23, 2016 10:36 pm, edited 1 time in total.

Post Reply