Re: Question on timer class
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRx.Click
Timer1.Interval = 1000
Timer1.Enabled = True
'Do something if they respond ???
'
'If they respond in time turn off the timer?
Timer1.Enabled = False
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
MessageBox.Show("Times Up!", "Timer")
End Sub
Something similar to this.
HTH
Re: Question on timer class
add a timer at design time, click on it and in properties set the interval to 1000 (milliseconds= 1 second).
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
MsgBox("boo")
Timer1.Enabled = False
End Sub
Re: Question on timer class
But if they respond in the time allotted then the timer will still fire.
Re: Question on timer class
Quote:
Originally Posted by RobDog888
But if they respond in the time allotted then the timer will still fire.
putting code in that commented area in button_click wont do anything unless he has an infinite loop, which is inefficient anyways
Re: Question on timer class
True :D, but I didnt know what other actions the poster had in place while he was waiting for a response.
Like an event for entering text in a textbox and pressing another button?
:p
Re: Question on timer class
hi Everybody
Thanks for the reply.....i'm have actually written a download process after the Timer1.Enabled = True and i wanted the timer to turn off if the download process complete on time.............but now.....i get this error "Handles clause requires a WithEvents variable"......what does this mean? can any 1 tell me this? thank u very much
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRx.Click
Timer1.Interval = 1000
Timer1.Enabled = True
'Do something if they respond ???
'
' If they respond on time turn off the timer
Timer1.Enabled = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
MessageBox.Show("Time out !!", "Timer")
End Sub
End Class
Re: Question on timer class
Quote:
Originally Posted by chioman
hi Everybody
Thanks for the reply.....i'm have actually written a download process after the Timer1.Enabled = True and i wanted the timer to turn off if the download process complete on time.............but now.....i get this error "Handles clause requires a WithEvents variable"......what does this mean? can any 1 tell me this? thank u very much
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRx.Click
Timer1.Interval = 1000
Timer1.Enabled = True
'Do something if they respond ???
'
' If they respond on time turn off the timer
Timer1.Enabled = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
MessageBox.Show("Time out !!", "Timer")
End Sub
End Class
that's probably because you copy/pasted the code hehe
You need to declare a variable first before you can reference an event for it. You can either do it manually, which I dont think would be easy for you..... .or
umm do this: you probably already have the button so the error should be from the timer. In design view of your form, add a TIMER control to your form and then double click on the timer. VS.NET will automatically generate the code for Timer_Tick event for you. Then you can put your timer code in there.