Dec 27th, 2005, 08:46 PM
#1
Thread Starter
New Member
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!
Dec 27th, 2005, 09:04 PM
#2
Hyperactive Member
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
Dec 28th, 2005, 02:31 AM
#3
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.
Dec 28th, 2005, 03:22 AM
#4
Fanatic Member
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
Attached Images
Last edited by noielen; Dec 28th, 2005 at 03:33 AM .
noister
<advertising link removed by moderator>
Dec 29th, 2005, 12:37 AM
#5
Fanatic Member
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!
Last edited by alkatran; Dec 29th, 2005 at 01:02 AM .
Don't pay attention to this signature, it's contradictory.
Dec 30th, 2005, 02:59 AM
#6
Thread Starter
New Member
Re: need help with a program having 10 second timer
Thanks a lot! and sorry if I posted at the worng place.
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width