Page 1 of 1
Repeat loop Serial Delay
Posted: Sun Dec 14, 2008 11:33 am
by hamlynart
Hi Folks,
I have the following repeat loop running but for some reason it doesn't send to the serial port until the end of the loop???
Code: Select all
on mouseUp
put the label of btn "Port" into thePort
repeat with x = 1 to 255
if fld "myFld" <= 255 then
add 1 to fld "myFld"
write fld "myFld" to driver thePort
wait 1
end if
end repeat
end mouseUp
Any thoughts or advice much appreciated.
Jim H
Posted: Sun Dec 14, 2008 1:36 pm
by Mark
Hi Jim,
Does this work?
on mouseUp
put the label of btn "Port" into thePort
repeat with x = 1 to 255 with messages
if fld "myFld" <= 255 then
add 1 to fld "myFld"
write fld "myFld" to driver thePort
wait 1 with messages
end if
end repeat
end mouseUp
Best,
Mark
Posted: Mon Dec 15, 2008 12:25 am
by hamlynart
Ahh Thankyou "with messages"!
However, although it
should work, instead it has exposed another problem - I need leading zeros - simplifying the problem:
Code: Select all
on mouseUp
put 000 into myVar
add 1 to myVar
answer myVar
end mouseUp
How do I get it to return 001 rather than just "1"?
Thanks
Jim[/u]
Posted: Mon Dec 15, 2008 12:33 am
by FourthWorld
set the numberformat to "000"
Posted: Mon Dec 15, 2008 12:44 am
by SparkOut
You might also make use of the "format" function.
will return myVar
as a string to length 3, padded as necessary with leading zeroes, as a rounded decimal integer. (The zero included before the length of 3 means that the length will be padded with leading zeroes, and the d means it will return a rounded decimal integer. You will find many other options looking up "format" in the dictionary.)
Note that this returns a string representation of the number. If you add 1 to "001" in Rev, it will work out that an arithmetic operation is required and evaluate the string accordingly (returning 2, not "002" - unless you use format to produce another string). Whatever system you are passing the data to may not work the same way.
Posted: Mon Dec 15, 2008 12:47 am
by hamlynart
Revolution is a miracle!
Thanks so much