Interrupting a counter

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Glenn Boyce
Posts: 137
Joined: Thu Jul 24, 2008 11:22 pm

Interrupting a counter

Post by Glenn Boyce » Mon May 11, 2009 12:02 am

I have set up a counter and I want to be able to to click on a button and get the count whilst it is still running. at the moment I have to stop the counter. Is there a way I can set the counter to run in the background so that I can still complete other tasks while it is running?

Code: Select all

put "" into tQty
  put "" into gN
  put fld "QTY" - 1 into tqty
  
  if gCompleted <> "" then
    put gCompleted + 1 into tcounter
    else
  put 1 into tcounter
  end if
  set the ustopped of me to false
  --put tqty - gCompleted
  repeat tqty - gCompleted times 
    put "" into gCompleted
  add 1 to tcounter
  wait 0.25 seconds
  put tcounter into N
  
   send "tmUpdateGauge N" to group g6
   put (N / tqty)*100 into gN
  
   send "tmUpdateGauge gN" to group g2
  wait 10 milliseconds with messages
  if the uStopped of me is true then
    put N into gCompleted
  exit repeat
end if
end repeat

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Contact:

Post by Mark Smith » Mon May 11, 2009 7:23 pm

If your waits are 'with messages', and it looks like 'gCompleted' is a global, you could put a function in your script:

Code: Select all

function getNumberCompleted
  return gCompleted
end getNumberCompleted
Then, in your button script, you could have

Code: Select all

on mouseUp
  put getNumberCompleted()
end mouseUp
which would put the value into the message box.

Best,

Mark

Glenn Boyce
Posts: 137
Joined: Thu Jul 24, 2008 11:22 pm

Post by Glenn Boyce » Mon May 11, 2009 9:51 pm

Hi Mark

I tried putting that code into my script and I get an error. Doesn't want to accept it for some reason. Also using gCompleted variable will only work if the counter is stopped. I use that variable to mark the point where I want the counter to restart again. I want to be able to click on a button and take the count as it is at that instant. That number would be in tCounter. I want to do it again a little later so that I am marking the beginning and end of an event. I want to store both numbers in a table and put the difference between them into another column. In the real world the count would be supplied by a machine and the tags represent "bad work" or waste. I want the operators to able to mark this bad work on the fly.
kind regards Glenn

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Mon May 11, 2009 10:59 pm

Glenn,

if you global tCounter (call it gCounter then)
add with messages to your wait 0.25 seconds
and use Mark's script in a button

Code: Select all

global gCounter
on mouseUp
   put getNumberCompleted() 
end mouseUp

function getNumberCompleted 
  return gCounter 
end getNumberCompleted
it should work. I tried it with a stripped down version of your repeat loop and it worked.
regards
Bernd

Glenn Boyce
Posts: 137
Joined: Thu Jul 24, 2008 11:22 pm

Post by Glenn Boyce » Thu May 14, 2009 2:23 am

Thank you

Post Reply