Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

halt code from form

Status
Not open for further replies.

ztm

IS-IT--Management
Jul 19, 2001
34
US
I'm working on a keno game for a school project that lets you play multiple consecutive games and tallies the results. i.e. if you play the same 7 numbers for 1000 consecutive games, how many times do you hit 7, 6, 5, etc. and calculates winnings and losses. I have two little problems...
1: While the code is executing, say 1000 games, I can't figure out how to stop it with a button.

2: Kind of related to 1, I have a delay slider that speeds up or slows down the play, but I want it to be "on-the-fly." Right now, you can only change the delay between games. Also, I want the delay to be from 0 to 2 seconds in .1 second increments (easy enough with the slider) What's not easy is if I set the slider to .5 seconds or below, there is no delay, and from .5 to 1 second, the delay is 1 second. I'm using

delay = slider.value
t = timer
do while timer - t < delay

I've also used
delay = slider.value
for t = 1 to delay
next t

but that's tough to regulate in relation to time.

Is there a way to just say... Delay = .2 seconds?

Any help would be appreciated.

Thanks.
 
To delay execution for .2 seconds (200 milliseconds) you can put the code in a timer and set the timer's Interval to 200, or use the Sleep API.

To stop execution with a button, you'll have to add a flag variable that gets set when the button is clicked, and check the value of the flag during the rest of the code. Since code will probably be executing when the button is clicked, you'll have to add a DoEvents statement to make sure the button_click() event gets added to the MSMQ and eventually gets called.

Good luck!

~Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
Public Declare Sub Sleep Lib &quot;kernel32&quot; Alias &quot;Sleep&quot; (ByVal dwMilliseconds As Long)


Wil Mead
wmead@optonline.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top