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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie - How to slow down counting??

Status
Not open for further replies.

spyder

Technical User
Jan 10, 2001
21
0
0
US
I'm new to VB. Is there a way to slow down how fast the following code executes? I am trying to have one number increase from 1 to 4 and the other decrease from 15 to 0 when the user clicks a command button. The event takes place, but way too fast...you only see 1 and 15 on the screen, hit the button, and then see 4 and 0. It speed counts! I want to actually be able to see the numbers change.

Private Sub cmdClock_Click()
For Qtr = 1 To 4
For Minutes = 15 To 0 Step -1
lblMinutes.Caption = Minutes
Next Minutes
lblQuarters.Caption = Qtr
Next Qtr
End Sub
 
couldnt you just put a delay routine inbetween the loops?

Code:
private sub delay(iSeconds as integer)
  Dim iLoop as integer

  iSeconds = iSeconds * 60000
  for iLoop = 1 to iSeconds
   'iterates for iSeconds
  next iLoop
end sub
Mark Saunders :)
 
I suppose I could do that, however, being that I am so new to this, I don't even know what that is yet! That must be in a future lesson of "Teach yourself VB in 21 days"??? I'll try it and it'll probably work. Thanks so much.
 
all this code does is

1. create a (dare i use the term) function called delay. ([tt]Private Sub Delay[/tt]) this particular routine can only be called from within the existing form due to the use of [tt]Private[/tt] as opposed to [tt]Public[/tt]
2. this routine accepts an integer (because the term [tt]Optional[/tt] is omitted from before the variable [tt]iSeconds[/tt] it is compulsory) - ([tt]Private Sub Delay(iSeconds)[/tt])
3. the passed integer ([tt]Private Sub Delay(iSeconds as integer)[/tt]) is then translated into an arbitary delay [tt]iSeconds = iSeconds * 60000[/tt] - in actual fact to get it to be real seconds you have to use the Timer control etc.
4. you then loop using the [tt]For..Next[/tt] construct for [tt]iSeconds[/tt] number of iterations

so as you can see, the term iSeconds is actually misleading (sorry!) - perhaps around day 8 you might tackle puting this simple sub on a form with a timer and equauting it to proper seconds and even making it accessible to all forms in the same project ... or even as a class available to all :)
Mark Saunders :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top