|
-
Nov 2nd, 2006, 12:33 AM
#1
Thread Starter
Hyperactive Member
[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
-
Nov 2nd, 2006, 12:36 AM
#2
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.
-
Nov 2nd, 2006, 01:25 AM
#3
Lively Member
Re: How to close a form in 30 seconds?
VB Code:
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Form_Load()
Sleep 30000
Unload Me
End Sub
-
Nov 2nd, 2006, 02:19 AM
#4
Re: How to close a form in 30 seconds?
 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.
-
Nov 2nd, 2006, 02:51 AM
#5
Member
Re: How to close a form in 30 seconds?
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
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
|