Results 1 to 5 of 5

Thread: [RESOLVED] How to close a form in 30 seconds?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Resolved [RESOLVED] How to close a form in 30 seconds?

    Dear Sir,

    When I open a form it should close automatically in 30 seconds. How can I do this using Timer? What is the code? Please help.

    Regards,

    Margaret

  2. #2
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: How to close a form in 30 seconds?

    Just set the timer's interval to 1000 (1 second), then every time the timer ticks, add 1 to a global variable. When it reaches 30, close the program.

  3. #3
    Lively Member djklocek's Avatar
    Join Date
    Aug 2006
    Posts
    107

    Re: How to close a form in 30 seconds?

    VB Code:
    1. Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    2.  
    3. Private Sub Form_Load()
    4. Sleep 30000
    5. Unload Me
    6. End Sub

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: How to close a form in 30 seconds?

    Quote Originally Posted by timeshifter
    Just set the timer's interval to 1000 (1 second), then every time the timer ticks, add 1 to a global variable. When it reaches 30, close the program.
    Or set the timer's interval to 30000 (30 seconds) then when timer ticks, close the program.

  5. #5

    Re: How to close a form in 30 seconds?

    Option 1
    VB Code:
    1. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    2. Private StopSleep As Boolean
    3. Private Sub Form_Load()
    4. Me.Show
    5. Dim i As Long
    6. For i = 1 To 30000
    7. If StopSleep Then Exit For
    8. Sleep 1
    9. DoEvents
    10. Next i
    11. End Sub
    12. Private Sub Form_Unload(Cancel As Integer)
    13. StopSleep = True
    14. End Sub

    Option 2
    Set the interval to 30000

    Option 3
    If you want it really long (eg. 20 minutes), you can workaround this with a second timer, set the interval to 1000
    VB Code:
    1. Private Sub Timer1_Timer()
    2. Static i As Long
    3. i = i + 1
    4. If i = 30 Then Unload Me
    5. End Sub

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