Repeat loop Serial Delay

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Repeat loop Serial Delay

Post by hamlynart » Sun Dec 14, 2008 11:33 am

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sun Dec 14, 2008 1:36 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Post by hamlynart » Mon Dec 15, 2008 12:25 am

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]

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

Post by FourthWorld » Mon Dec 15, 2008 12:33 am

set the numberformat to "000"
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

SparkOut
Posts: 2944
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Mon Dec 15, 2008 12:44 am

You might also make use of the "format" function.

Code: Select all

format("%03d",myVar)
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.

hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Post by hamlynart » Mon Dec 15, 2008 12:47 am

Revolution is a miracle!

Thanks so much

Post Reply