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! :|

1. Place a timer control on the form
2. Interval = (what ever you want)
3. Write the following code under timer event

private sub timer1_timer

unload me

end sub

or if you want to load a form
then write
(name of form).show
the form will appear

Make use of the timer control. Try some things out and if they dont work for you, then show your code

it doesn't work..

i use the the codes u gave to me..

private sub timer1_tick

interval = 10

- the interval is not declared and the unload..

what code should i use! :(

it doesn't work..

i use the the codes u gave to me..

private sub timer1_tick

interval = 10

- the interval is not declared and the unload..

what code should i use! :(

Try this:

Private sub Form_Load()

Timer1.Interval = 5000 'for 5 second and 10000 for 10 seconds

End Sub

Private sub Timer1_tick()

Unload Me

End sub

Here's some code I use to Create a delay...

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...
End Sub

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
End Sub

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.

NOTE: tic is a Public Variable

Set the timer interval to 5000 in the Properties window and put this code on a timer control.

If Timer1.Interval = 5000 Then 'Timer1 is the default name, change if necessary
Unload Me
End If

Edited 5 Years Ago by abelingaw: n/a

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.
End Sub

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.

just set the timer interval property to 10000 for 10secs or 5000 for 5secs and make sure that Enabled property is set to true.

Private Sub Timer1_Timer()
   Unload Me
End Sub

Wait. i think you're using .NET? That way you can use this. Set the interval property of the timer to yuor desired interval 10000 = 10 seconds. and enabled to true

End Sub

Right when you load the Splash Screen or Form, in the Load event enable the timer.

Or, if the timer is actually on the form you want to close just set the enabled property to true in the properties panel.

This article has been dead for over six months. Start a new discussion instead.