hi there! guys can you help me how the form will automatically close in 5 or 10 seconds and so on? like a countdown timer, when the time runs out then it will close automatically? give me some specific codes. tnx! :|
Sub delay(timeout As Long)
Dim OldCap As String
Dim OldFont As Long
' Here I am saving the Button Caption and Font
OldCap = MN.cmdRun.Caption
OldFont = MN.cmdRun.FontSize
MN.cmdRun.FontSize = 14
' timeout is Delay Time in tenths of a Second
' Here is where I turn the Timer On
MN.Timer1.Enabled = True
Tic = 0
Do While Tic < timeout
MN.cmdRun.Caption = Str((timeout - Tic) / 10)
' Do Events allows other stuff, like keypresses, button clicks, etc. to
' happen while you are in the delay loop.
' here I restore the Button Caption
MN.cmdRun.FontSize = OldFont
MN.cmdRun.Caption = OldCap
' hmmmmmmm I didn;t turn the timer back off????
' gotta wonder if I forgot, or am doing it elsewhere...
On the form where you've placed your Timer add
Private Sub Timer1_Timer()
' The variable tic will be incremented each time the time interval expires.
Tic = Tic + 1
Do not forget to either programmatically set your .Interval or set it in your Properties when you place the timer on the form. I am using a value of 100 or a tenth of a second.
The Timer control has a few important properties. They are pretty simple to use. But you must understand a few things:
(1) You must set the enabled property to True, before they start. Timer1.enabled = True You can do this with a command button or have the property enabled at design time. By default it is not enabled at design time.
(2) You also must understand the interval property. Each tick of the timer is worth 1 millisecond. So, you need 1000 ticks for each second: Timer1.interval = 5000 That would give you 5 seconds.
And finally, (3). You must implement your desired code in the Timer event.
Private Sub Timer1_Timer()
' Code you wish to see occur.
' As previously posted here: [B]Unload Me[/B] should be a good choice.
' Many coders also use this event to turn the timer off: e.g. [B]Timer1.enabled = false[/B]
' A nice technique is the following: [B]Timer1.enabled = Not Timer1.enabled[/B]. This toggles the timer either on or off every time the Timer Event occurs.
You'll find the area is automatically created for you in your IDE when you click on the only available event for the Timer control in Code View. Double clicking on the Timer Control on your form will do the same.
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...