Written By TheVBProgramer.
The TIMER Control
The Timer control allows you to perform a task at a specified interval or to wait for a specified length of time.
Timer Example 1
Control Property Value
Command Button (Name) cmdStart
Caption Start Timer
Command Button (Name) cmdStop
Caption Stop Timer
Timer (Name) tmrTest
Enabled False
Interval 250
Your form should look something like this:

Consider the following facts about the Timer control:
Ø It is not visible to the user at run-time
Ø The actions that you want to happen at the specified interval are coded in the Timer's Timer event.
Ø You specify the interval that you want actions to occur in the Timer control's Interval property. The value is specified in milliseconds (1000 milliseconds = 1 second). In the example, the value of 250 will cause the Timer event to fire every quarter of a second.
Ø You turn the timer "on" or "off" by setting its Enabled property to True or False, respectively. The Enabled property is set to True by default.
Private mintCount As Integer
Private Sub cmdStart_Click()
mintCount = 0
Cls
tmrTest.Enabled = True
End Sub
Private Sub cmdStop_Click()
tmrTest.Enabled = False
End Sub
Private Sub tmrTest_Timer()
mintCount = mintCount + 1
Print "Timer fired again. Count = " & mintCount
End Sub

Download the VB project code for the example above here.
Timer Example 2
The Timer control can be used to make an object on your screen appear to blink. This is done by toggling the Visible property of the object on and off at short intervals. The Visible property is available to nearly all controls – it is a Boolean property that determines whether or not the control is visible to the user at run time by setting its value to True or False (it will always be visible at design time). To build a simple demo, perform the following steps.
lblProcessing.Visible = Not lblProcessing.Visible
Download the VB project code for the example above here.
Comments
move controls at run time
Hello friends,
can u tell me how can i move control at run time?
controls like button,textbox etc....
Hello
Can i download this lesson?
Database
There are three text boxes( text1, text2 & text3) on a form bound to a database table. text1 and text2 are bound to fields of the table. I want to show the value of multiplication of two boxes. Plz reply. thanks.
timer on all forms
i need a timer in all forms..the timer control is in form 1 then the time countdown activates in all other forms.. is it possible? please help me!
. yes it is possible. put an
. yes it is possible.
put an label to your form rename it lbltimer , change the text to "0" then
put this code in lbltimer
lbltime.Text = lbltime.Text + 1
If lbltime.Text = 5 Then
btnOK.Enabled = True
Timer1.Stop()
Form2.Show()
Me.Hide()
.....VB 8 codes !
VB 6 animation program.
Hi there!
I made one simple vb 6 program. I did one animation of one engine running and one fan or cooler runnig too. It individually runnig if I push Start button of it object either engine or fan. The question is. I would like to add two buttons one Auto and another Manual. When I push or click the Manual button the fan can not running If I start engine. Did you get the point? I did engine runnig together with fan or cooler but I would like to add those two buttons. If I push Auto the two engine and cooler can running together but if I push Manual button the cooler can not running until I change pushing Auto button. Did you get it?
Hi I really need help. I
Hi I really need help. I want to make a program where when i click on a button the timer starts to make labels appear with intervals of 5 seconds....should i make a specific timer for each button? and how do i call the timer function in the required button?
.put an label to your form
.put an label to your form rename it lbltime , change the text to "0" then
put this code in your button
lbltime.Text = lbltime.Text + 1
If lbltime.Text = 5 Then
btnOK.Enabled = True
Timer1.Stop()
Regarding timer
I m new to VB6 and I want to display time in visual basics 6.0 i.e in the this manner 00:00:01, 00:00:02, 00:00:03 and so on.. and that too one after the other.. can we do this? plz reply m badly in need
Counter Timer request
'Just mail me at voicaalin30@yahoo.com for any problems.
'As you can see i am not using any commands buttons
'just labels.
'Just put 12 labels like me and copy and paste the code.
'My first 6 labels have caption 0 (zero)
'label 7 and 8 with caption :
'label 9 as Start
'label 10 as Stop
'label11 as Resume ' or continue
'label 12 as Reset
Private Sub Form_Load()
Me.Caption = Date
Label11.Visible = False
Label10.Enabled = False
End Sub
'Label Stop
Private Sub Label10_Click()
Timer1.Enabled = False
Label10.Visible = False
Label11.Visible = True
Label9.Enabled = False
End Sub
'Label Resume
Private Sub Label11_Click()
Timer1.Enabled = True
Label11.Visible = False
Label9.Enabled = False
Label10.Visible = True
End Sub
'Label Reset
Private Sub Label12_Click()
Timer1.Enabled = False
Label9.Enabled = True
Label10.Visible = True
Label10.Enabled = False
Label11.Visible = False
Label1.Caption = 0
Label2.Caption = 0
Label3.Caption = 0
Label4.Caption = 0
Label5.Caption = 0
Label6.Caption = 0
End Sub
'Label Start
Private Sub Label9_Click()
Timer1.Enabled = True
Label10.Enabled = True
Label9.Enabled = False
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Label1.Caption + 1
If Label1.Caption = 10 Then
Label2.Caption = Label2.Caption + 1
Label1.Caption = 0
If Label2.Caption = 6 Then
Label3.Caption = Label3.Caption + 1
Label1.Caption = 0
Label2.Caption = 0
If Label3.Caption = 10 Then
Label4.Caption = Label4.Caption + 1
Label1.Caption = 0
Label2.Caption = 0
Label3.Caption = 0
If Label4.Caption = 6 Then
Label5.Caption = Label5.Caption + 1
Label1.Caption = 0
Label2.Caption = 0
Label3.Caption = 0
Label4.Caption = 0
If Label5.Caption = 10 Then
Label6.Caption = Label6.Caption + 1
Label1.Caption = 0
Label2.Caption = 0
Label3.Caption = 0
Label4.Caption = 0
Label5.Caption = 0
End If
End If
End If
End If
End If
End Sub
countdown program
Could any1 please send me a simple countdown program that displays the countdown of 60 seconds on a label in a single form?
Count down
Add a label to the form.
The label caption should be the starting amount ( eg: 60 )
Add a timer to the form.
Set the timer interval ( eg: 100 )
In the timer event, add the code...
Label1.Caption = Label1.Caption - 1
This will count down from 60...... Until you stop the timer.
( eg: If label1.caption = "0" the Timer1.enabled = false )
All the best!
Hi Guys can any one guide me
Hi Guys can any one guide me on the vb code for Remote controlled car from pc parallel port
I managed to write code for up,down,right,left, but i want guidance for preset path and memories the path.
Thanks in advance.
continuously count over and over until required to stop
Im new to VB6. Can anybody please help me how to create a simple program which is intended to continuously count number from 1 up to 100 repeatedly without stopping unless I press the button stop. At the same time, when I press stop button the screen will show any random number.
Here's my code but something gets wrong everytime I run this. Can you please help me figure out why this happen or could you please provide a better code.
Private Sub Command4_Click()
Dim x As Integer
Command5.Caption = "SELECT"
x = 1
For x = 1 To 100
Text0.Text = x
If Command5.Caption = "STOP" Then
End
End If
If x=100 then
x = 1
End if
Next x
End Sub
Private Sub Command5_Click()
Command5.Caption = "STOP"
Call Randomize
Text0.Text = 1 + Int(100 * Rnd())
End Sub
The Solution
'The general Declarations
Private count10 As Integer
'The Command Box Which Starts The numbers moving from 1 to 100.
Private Sub Command1_Click()
'The next line should be used only if you want to to start from 0 every time you click "Start"
'count10 = 0
Timer1.Enabled = True
End Sub
'The Command Box Which Stops The numbers moving from 1 to 100 and Displays a Random Number.
Private Sub Command2_Click()
Randomize (1)
count10 = 0
Timer1.Enabled = False
count10 = Int(Rnd * 100)
Label1.Caption = count10
End Sub
'The Code to Be Executed On Form Load.
Private Sub Form_Load()
Timer1.Enabled = False
End Sub
'The Coding In The Timer Controls Timer Attribute.
Private Sub Timer1_Timer()
count10 = count10 + 1
If count10 = 100 Then
count10 = 1
End If
Label1.Caption = count10
End Sub
Objects Used.
2 Command Boxes
1 Label
1 Timer Control
Enjoy.......
And Thanks For The Exercise
timer
I want to make a project which will make a font smaller to larger and then it will back larger to smaller at a time. I use this code but I made it half complete. its not working. it makes the font size larger but I can not make it smaller.
the code I use
Private Sub label1_Load()
Label1.Fontsize = Label1.Fontsize + 5
End sub
Interval was 500 but its growing bigger and bigger. how I can stop it and how I can make it smaller from the larger size.
It will be great help for me if any body can solve this problem
This it is me code for your request
I am using 2 timers to go back the action
and my logo on form load
Both timers must be enabled = false
with your interval preset.
The second label it is to have a stop and you can fix it as visible = false
I am a beginer in VB6 so i belive there must be a easy way to do this but this it is
my way
Private Sub Form_Load()
'label1.caption = "wfc"
Label1.FontSize = Label1.FontSize + 20
Timer1.Enabled = True
Label2.Visible = False
End Sub
Private Sub Timer1_Timer()
Label2.Caption = Label2.Caption + 1
If Label2.Caption = 5 Then
Timer1.Enabled = False
Label1.FontSize = Label1.FontSize - 20
Label2.Caption = 0
Timer2.Enabled = True
End If
End Sub
Private Sub Timer2_Timer()
Label2.Caption = Label2.Caption + 1
If Label2.Caption = 5 Then
Timer2.Enabled = False
Label1.FontSize = Label1.FontSize + 10
Label2.Caption = 0
Timer1.Enabled = True
End If
End Sub
STOPWATCH with interval REPORTER
Hi,
I need a stop watch code in VB which be able to record and report:
1- how many times is being used?
2- the time of both pressing the START button and the STOP button
3- the total time duration
*** this program will be used to record the duration of breaks of the employees in a company***
thanks alot...wait for your reply
Using a timer within a control structure
I am trying to use a code segment as follows:
For I = 1 to 15
For J = 1 to 10
Count down from 30 seconds, displaying the countdown
Next J
Next I
If I put my countdown code within the Timer event, and have the timer set for a 1 sec interval, having the Timer.enable in ForNext J, the nested ForNext structure has completely executed before the Timer can complete the first interval. If I put a delay loop controlled by a Done flag in the ForNext structure, we get an infinite loop and the program crashes. Any help solving this problem would be greatly appreciated.
How to display timer in mm:ss:ms
Hello.
I would like to enquire regarding how to i go about displaying the timer in the format of "mm:ss:ms" (min: sec: millisecond). Have been looking online for references for days, tried out quite a number of codes too but dont seems to be able to find one as mostly are those displaying in hh:mm:ss but i need it in milliseconds.
Hope to be able to find someone who can guide me on this as i'm pretty new in Visual Basic. Thank you.
Multiply/Divide?
I will use "timer" as the timer's name. "msCount", "secCount", and "minCount" will be the respective time variables. Try setting timer's interval to 1 and:
Private Sub timer_Timer()msCount = msCount + 1
If msCount > 1000 Then
msCount = msCount - 1000
secCount = secCount + 1
end if
If secCount > 1000 Then
secCount = secCount - 60
minCount = minCount + 1
End If
End Sub
Well darn, syntax highlighting doesn't work :P
Hopefully that should help!
If you use > 1000 then the
If you use > 1000 then the timer will count to 1001 mili seconds before switching. Should be >= 1000 or > 999
Timer not working with winsock
Hi,
I'm developping an application that reads emails from a server.
I have set the interval of the timer1 to 1000 *30 (i.e. 30 seconds).
In the timer1_timer () subroutine I called another subroutine which makes a connection
with the server using
Winsock1.RemoteHost "hostname"
Winsock1.RemotePort "hosr port"
Winsock1.Connect
and then reads the emails etc.
then dissconnects from the server, and after 30 seconds or whatever repeats the cycle:
connecting to the server
reading emails
dissconnecting from the server.
The problem is that the timer run through the cycle mentioned above only once,
after 30 seconds it does not do anything.
Please help me.
Thanks a lot, appreciate your help
Aiman
real time in vb
anyone know how to write a code for real time counter? Means it can display like a clock??
Bad Code
You above example
"
Private Sub cmdStart_Click()
mintCount = 0
Cls
tmrTest.Enabled = True
End Sub
Private Sub cmdStop_Click()
tmrTest.Enabled = False
End Sub
Private Sub tmrTest_Timer()
mintCount = mintCount + 1
Print "Timer fired again. Count = " & mintCount
End Sub
"
It doesnt work here, all that this produces is
Timer Fired Again. Count = 1
Timer Fired Again. Count = 1
Timer Fired Again. Count = 1
Timer Fired Again. Count = 1
You get the point, you should verify your code here, cause when I am learning i like to go thru and try to creat it myself and I couldnt, so I tried copying your code and got the same result... Wasted a half hour trying to find what I did wrong only to find my example code is inncorrect. Its hard to fix the teachers code.. lol
Its casue you dont show to Declare the "Private mintcount as integer"
how to show a label as a welcome window using timer for 3 second
Hai Friends,
I finished my project of Production and Rejection related one using ADO. In I design a welcome and license detail of my project.During MDI form initial it display for 3 seconds. how to write code for that i paste the timer control in MDI form but i dont know how 2 write code for this
Please help me
Thanks,
Ramkumar.C
duration
Can anyone help me how to make time duration?
i really don't know how...
hope you'll reply as soon as possible...please!!!!
Thanks
thanks for provide me help
thanks for provide me help
Timer controlbox not found
I want to create a splash screen in my excel project. For this I need a timer function. But in the toolbox the timer button is not showing.
Can anyone please tell me how to add timer in the toolbox....???
Delay Timer
Trying to create a delay timer. Thus far all it does is lock up VB6
Trying to do something, wait some time frame, then proceed with next step of code.
Seem simple but I just don't get it.
Any insight would be greatly appreciated
thank you
Option Explicit
Dim Done As Integer
Dim uh As Integer
Private Sub Form_Load()
Done = 0
Timer1.Enabled = False
Timer1.Interval = 1000
Call RunThis
End Sub
Private Sub RunDelay()
Timer1.Enabled = True
Do
Loop Until Done <> 0
Exit Sub
End Sub
Private Sub RunThis()
uh = 1
Call RunDelay ' 1 second delay
uh = 2
End Sub
Private Sub Timer1_Timer()
Done = Done + 1
Timer1.Enabled = False
End Sub
<>
Delay Timer
The delay you created is not running because you do it when the form load into the memory. When the timer1.enabled=true , the command is not working , so the "done" variable is still 0. Then the computer still doing the loop till it get bug.
Thanks ++ Question
Hello!
I Love this site its exellent!
I Have a question...
Can you give me a code so like I Have a textbox. and i want to save what ive written in it.
well make a button for that to save. and a button to load the .txt file it was saves as ?
please give me a code for that i really need it!
thanks!
too many timers?
I am writing a program that runs three forms at a time. Each of the three forms has three timers of which, any two are running at a time. When I turn on the timers on the second and third forms, the timers on the first form stop functioning. Whats up with this?? I have done this before and it has always worked. Does anyone have a clue what could be going wrong?
Thanks,
Huff
About too many timers
About too many timers
module
hey!!!...
someone can tell to me what is the proper way to declare in module??.... and what is the easier way to declare??...
email me at: dinzkie006@yahoo.com
timer countdown easy
if yah want to countdown thn use:
Dim i as integer
private sub form_load()
i=5000 '50 sec's
timer1.interval=1
timer1.enabled=true
end sub
private sub timer1_timer()
i=i + 1
lbl1.caption="i"
if i = 0 then
i=i -1
lbl.caption= "i"
end
end if
end sub
simple countdown!
timer
help me.....help me.....plzzzz!!!!!!
i wish to know to make a timer or a clock for the log in and log out....for example....the user use the computer and he/she log in the time when he/she start and compute the No. of hours after he/she use the computer...
i hope you answer my question. i need it on my project..
Thanks!!
Save Log time
HI, im on a project right now like a Internet cafe busines.
where there is a Server and a Client.
i have found a way to record the Log In time and the Log Out Time, and the Total timed use.
using the ADODB and some SQL codes via MS access Database
where, when the user Log in, then it is recorded once Loged.
declaring this on a Module------------------
'create a new Connection
public myCon as new ADODB.connection
'create a new Record Set
public rsLoged as new ADODB.recordset
'create an event
Public Sub myEvent()
myCon.open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source= "C:\...Location.mdb;persist Security Info=False"
myCon.CursorLocation = adUseClient
End Sub
modules ends here----------------------
now on the form------------------
Private Sub Form_Load()
'call the event here
Call myEvent
'declare a variable
dim mySQLcode as string
'now some SQL codes must be added.
' ex: [Variable] = "select [*,Fields] from [table]"
mySQLcode = "Select * from LOGED"
'[recordset].open [variable], myTimeOutCon, adOpenDynamic, adLockOptimistic
'[recordset].movelast
rsLoged.open mySQLcode, myTimeOutCon, adOpenDynamic, adLockOptimistic
rsLoged.MoveLast
cmdLogOut.enable = false
form ends here---------------------
----------------------------------------
now on your Log in Button clicked.
'asuming i have 3 fields in my DBase, and 2 buttons
'field(0) = Log In
'field(1) = Log Out
'field(2) = Total Time.
'On Log In
private sub cmdLogin_clicked()
dim myLogin as string
myLogin = time
SS = 0
MM = 0
HH = 0
timer1.enable = true
timer1.interval = 1000
'the rest you want to add on then button
end sub
'On Log Out
private sub cmdLogOut_clicked()
rsLoged.movelast
rsLoged.addnew
reLoged.fields(0) = myLogin 'this is the variable you declare on the login button
reLoged.fields(1) = time 'this is the system time
reLoged.fields(2) = lblTimer 'this is a label contaning the Time Consumed
rsLoged.Update
end sub
-----------------------------------
'time consumed is the set apart by Hours, Minutes and Seconds
declaring HH, MM, SS as integer will do.
and HO, MO, SO as string
on a timer1
private sub timer1_timer()
SS = SS + 1
With lblTimer
If SS >= 10 Then
SO = "" & SS
End If
If MM >= 10 Then
MO = "" & MM
End If
If HH >= 10 Then
HO = "" & HH
End If
.Caption = HO & ":" & MO '& ":" & SO this is invisible.
End With
end sub
'this is working for me, this will not compute for the interval of the Log in and Log out but
'lets say it does cause it display the time consumed from the time you Log In
'i.e. Login:1:00pm; Logout:2:25; Consumed:1:25;
end sub
-------------------------------
now for viewing the record--------------
on a new form
add a datagrid view on the form 'get it on the components
private sub form2_load()
Dim SQLTimeOut As String
SQLTimeOut = "select * from LOGED"
rsLoged.open SQLTimeOut, myTimeOutCon, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rsData
end sub
'thats all: HOPE this is HELPUL to you
(^_^),\m/
I Forgot to..
remember the timer1_timer()?
Im sorry, i forgot the timer, its incomplete.
here is the complete code for it :)
Private Sub TimerStart()
SS = SS + 1
HO = "0" & HH
MO = "0" & MM
SO = "0" & SS
with lblTimer
If SS >= 10 Then
SO = "" & SS
End If
If MM >= 10 Then
MO = "" & MM
End If
If HH >= 10 Then
HO = "" & HH
End If
.Caption = HO & ":" & MO '& ":" & SO this is invisible
end with
'this is what i forgot to enter.
'this is the counter actualy
'when SS = 59, the MM will increment by 1, and same to HH when MM does.
If MM = 59 And SS = 59 Then
HH = HH + 1
MM = 0
SS = 0 - 1
consPrc = consPrc + 20
Else
If SS = 59 Then
MM = MM + 1
SS = 0 - 1
End If
End If
End Sub
tutorials
I just wanted to thank you for your tutorials I am a mature student trying to learn vb . I get 2 hours tuition per week.
The jargon used in books and some other tutorials make it very difficult to advance therefore simply explained procedures are much appreciated
Thank you for your efforts
my question is....
how to move text on form with the help of timer control......
plz do answer.........
if you still need help ....
if you need help with code send it to me and tell me what you want...i will fix it and highlight all changes....happy coding...
timer counting down
i need help on a timer with a label displaying the time 30 sec's counting down to 0
need help badly
Counting down from 30 sec to 0
Hey guy, try this.
First set timer interval to 1000
Dim i as integer
Private Sub Form_Load()
i = 30
End sub
Private Sub Timer1_timer()
i = i - 1
label1.Caption = i
If i = 0 then Timer1.Enabled = False
End Sub
I think I'll work.
not well done
it doesn't work at all
IT Works... Thanks To Previous Writer....
ALL THE CODING HAS BEEN DONE BY PREVIOUS PERSON.
I Just Added 1 Line.(In Bold)
3 Things have to be Done.
1 label (here it is Label1)
1 Timer Control(here it is timer1) [The interval property has to to set to 1000 (1000MillSec = 1 Sec)]
Dim i As Integer
Private Sub Form_Load()
i = 30
Timer1.Enabled = True
End Sub
Private Sub Timer1_timer()
i = i - 1
Label1.Caption = i
If i = 0 Then Timer1.Enabled = False
End Sub
countdown timer
help me..help me.. plssssssss..need it badly..
can pls.. someone help me with my final project.. VB codes
i need help in coding my timer..
20:00(20 hrs.) with start - stop button..
and it should be visible..
thnxs..
I would like to know how to
I would like to know how to intergrate my forms
how 2 enable timer from d followin condition
suppose i have 3 shapes as 1,2,3. these are coded in such a way with 3timers that firstly 1 is visible & others are not & after interval 1000, it bcomes invisible & 2 is now visible. similarly this process repeats for 3 & again back for 1. if i want to enable another timer4 with a click of a command button when 1 is visible or timer5 when 2 is visible or timer6 when 3 is visible , then what code should i write on the click event of command button.
You would simply use an if
help me plz
im a student from the philippines. i cant figure out how can i do this scenario, i have 1 label box but it can change its content by means of timer?? i cant do it.. can u help me....
1 label box
controlled by a timer
with different captions
plz help me thanks
three timers to work together.... or setting two intervals...
Please!!! Help!!!
i need three timers working together. We're working on a timed-traffic-light project. The traffic lights (red, yellow and green) need to blink alternately (ex: red glows red then after interval yellow glows yellow then another interval and green flashes).
Do you know how?
Thanks anyways....
hey guys i have problem i
hey guys i have problem i want to make game with shape and i dont know how to put timer in. can u help me??
stop watch ticking from 10 to 0
Can anyone help me???
I want to create a project but for that project i'll need a stop watch ticking from 10 to 0.
And i need to print how much time is left until watch get's to 0.
Please HELP!!!
Private Sub
Private Sub Form_Load()
Label1.Caption = 10
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Label1.Caption - 1
If Label1.Caption = 0 Then
MsgBox ("Time is out"), vbInformation
Timer1.Enabled = False
End If
End Sub
Ten minute countdown timer
To make a start-stop watch
I suggest a simple method to make a start-stop watch : Take the first exemple of this toturial, look at for the variable mintCount:
at line mintCount = mintCount + 1
we rewrite : " mintCount = mintCount + tmrTest.Interval" .
Make a Textbox on the main Form (for exemple : with the name txtTime).
Then, the text of this Textbox will be set : txtTime.Text = FormatNumeric(mintCount/1000,2)
'Format a numeric number with 2 numbers after '.'
'That give us : second.milisecond
But this solution has a problem: If we choose a small value of Interval of Timer (for ex: 100, 200), the elapsed time is displayed on the TextBox is incorrect because the program takes a few moment to execute the syntax.
However, if we use a higher Interval value (for ex : 500), we can avoid this problem.
Countdown?!
can you please teach me how to make a timer countdown...!!!
i really dont know how...
countdown timer as it will appear as this "10:00"
hope you'll reply as soon as possible...please!!!!
pause nd reset options??
can anyone help me with getting the timer start stop nd reset.....as we do exactly with an start stop watch????
another example
i wish to know how to make an actuall timer, for a game... for example... the user is being timed as to their efficiency in doing a test... (15 questions)...
i understand that i'll need 2 timers and a lable which desplays the time going up and starting from 0 minuts... can u post something like that up?? thanks
Post new comment