need help with a program having 10 second timer
A program with 10 second timer
(label here) Enter Password: (texbox here)
(label here) time remaining: (timer here)
the user will only be given ten seconds to type in the password and after ten seconds a message box will appear. I cant really figure out the codes for the 10 second timer and the message box..Please help me! thank you! :blush:
Re: need help with a program having 10 second timer
VB Code:
Private Sub Timer1_Timer()
Text1.Visible = False
Timer1.Enabled = False
MsgBox "Too Late"
End Sub
timer set to 10000
not sure about the listing time left
Re: need help with a program having 10 second timer
This is not an appropriate post for this forum. It should have been posted in the forum for the language you are using. Is this VB.NET? If so, just add a Timer object to your form and set its Interval to 1000 (1 second). Then, in the Tick event handler you display the time remaining in the Label. You would then test whether the time remaining has reached zero and, if so, stop the Timer and display the MessageBox.
1 Attachment(s)
Re: need help with a program having 10 second timer
if it's vb... do it like this
add 1 timer, 2 labels, 1 button, 1 textbox to your form
then add this code below:
VB Code:
Dim ctr As Integer
Private Sub Form_Load()
ctr = 10
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
If ctr < 1 Then
MsgBox "Install typing tutor, hehehe!", vbCritical, "10 sec"
Else
Me.Label2.Caption = ctr - 1 & " s"
End If
ctr = ctr - 1
End Sub
:mad:
Re: need help with a program having 10 second timer
This shouldn't be done with a timer. That's just spaghetti code. A much better way would be to use GetTickCount, Sleep and DoEvents to wait it out.
VB Code:
'Declarations for gettickcount and sleep here
private sub enterpassword()
dim N as long
msgbox "GO"
n = gettickcount + 10000 '10 seconds = 10 000 milliseconds
while gettickcount < n
sleep 25 'wait 25 milliseconds
doevents 'catch key events and such
wend
msgbox "STOP"
end sub
To the person using the program it runs exactly the same, and it won't even use much processor time thanks to sleep!
Re: need help with a program having 10 second timer
Thanks a lot! and sorry if I posted at the worng place. :)