Question:
How to get the Timer work in VB?
Senthil
2006-06-16 22:51:04 UTC
I'm doing a Puzzle game in VB. For that I need to time the answers. How do I do that?
Four answers:
_anonymous_
2006-06-25 15:12:37 UTC
1. Place a Timer control on your form.

2. Set its Interval property to 1000(for 1 sec., 1000 millisec.), so the Timer(or Tick) event will be called every n

milliseconds, determined by the Interval property.

3. Put this code into the Timer(or Tick) event(first define an Integer variable at the top of the form's code):



If seconds = Then

MsgBox("Times up!")

Exit Sub

End If

seconds = seconds + 1



Diring design, you can set the Timer's Enabled property to False to disable the Timer. To change states(enabled/disabled), use:

.Enabled = Not .Enabled



:)
i_am_the_answer
2006-06-16 23:25:57 UTC
drag and drop a timer into the ur FORM window from the windows components toolbar(let its name be timerForU).. there is a propety for timer called: interval. first set value for it before starting the timer



code: timerForU.interval=500

ie: 500 milliseconds



then to start the timer: timerForU.start()



500 indicates the time in millisec after which the timer will tick. (tick is an event generated by the timer after each 500 ms). ie: tick event arises at: 500ms, 1000ms, 1500ms... till the timer is stopped by stop() method



event handler: to handle the timer tick event:



private sub timerForU_tick(byval sender as System.Object, byval e as System.EventArgs) handles timerForU.Tick

// event handling code goes here

end sub



to sum up:

1.) set interval

2.) start timer

3.) handle events and stop the timer whenevr needed

4.) handle exceptions
Michael R
2006-06-16 23:59:51 UTC
ok since your desgning a game let me give you some advice if you want a better time approx then you need to write a better timing device GetTicks API or the call in .net will do it but if you just need it for rudimentry game loop then a timer (dragged on or invoked in code) and a timmer1.enabled=true; boolean value will dictate what state it is in the tick event will do the trick good luck



- Mike roth
© 2007. Sammy Z.
2006-06-16 23:14:41 UTC
read all about it


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...