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
Printable View
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
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.
VB Code:
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Sub Form_Load() Sleep 30000 Unload Me End Sub
Or set the timer's interval to 30000 (30 seconds) then when timer ticks, close the program.Quote:
Originally Posted by timeshifter
Option 1
VB Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private StopSleep As Boolean Private Sub Form_Load() Me.Show Dim i As Long For i = 1 To 30000 If StopSleep Then Exit For Sleep 1 DoEvents Next i End Sub Private Sub Form_Unload(Cancel As Integer) StopSleep = True 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:
Private Sub Timer1_Timer() Static i As Long i = i + 1 If i = 30 Then Unload Me End Sub