Results 1 to 6 of 6

Thread: need help with a program having 10 second timer

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    4

    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!

  2. #2
    Hyperactive Member Rattled_Cage's Avatar
    Join Date
    Dec 2005
    Posts
    315

    Re: need help with a program having 10 second timer

    VB Code:
    1. Private Sub Timer1_Timer()
    2. Text1.Visible = False
    3. Timer1.Enabled = False
    4. MsgBox "Too Late"
    5. End Sub

    timer set to 10000
    not sure about the listing time left

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Fanatic Member noielen's Avatar
    Join Date
    Nov 2005
    Location
    Cebu, Phil.
    Posts
    680

    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:
    1. Dim ctr As Integer
    2. Private Sub Form_Load()
    3. ctr = 10
    4. Timer1.Interval = 1000
    5. End Sub
    6. Private Sub Timer1_Timer()
    7. If ctr < 1 Then
    8.     MsgBox "Install typing tutor, hehehe!", vbCritical, "10 sec"
    9. Else
    10.     Me.Label2.Caption = ctr - 1 & " s"
    11. End If
    12. ctr = ctr - 1
    13. End Sub
    Attached Images Attached Images  
    Last edited by noielen; Dec 28th, 2005 at 03:33 AM.
    noister
    <advertising link removed by moderator>

  5. #5
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860

    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:
    1. 'Declarations for gettickcount and sleep here
    2.  
    3. private sub enterpassword()
    4. dim N as long
    5.   msgbox "GO"
    6.   n = gettickcount + 10000 '10 seconds = 10 000 milliseconds
    7.   while gettickcount < n
    8.     sleep 25 'wait 25 milliseconds
    9.     doevents 'catch key events and such
    10.   wend
    11.   msgbox "STOP"
    12. 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.

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    4

    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
  •  



Click Here to Expand Forum to Full Width