Understanding the timer control

Level:
Level1

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

 

  • Start a new VB project and place two command buttons and a timer control on the form. Set the properties of the controls as follows:

 

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.

 

  • Place the following declaration in the Form's General Declarations section:

 

Private mintCount As Integer

 

  • Code the Click event for the two command buttons and the Timer event for the timer control as follows:

 

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

 

  • Run the program. Click the "Start Timer" button. Messages will appear on the form every quarter of a second. They will stop when you click the "Stop Timer" button. A sample run might look like this:

 

 

 

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.

 

  • Start a new VB project.
  • Place a label on the form and name it lblProcessing. Set its Caption to Processing . . . Please Wait. Set it to a large font and set its Forecolor property to the color of your choice. Center it on your form.
  • Place a timer on the form and name it tmrBlink. Set its Interval property to 250.
  • In the tmrBlink_Timer event, place the following single line of code:

 

lblProcessing.Visible = Not lblProcessing.Visible

 

  • Run the project. The label will blink. After an appropriate period of observation, close the form.

Download the VB project code for the example above here.

If you enjoyed this post, subscribe for updates (it's free)

Please Help!!!! I need to

Please Help!!!!

I need to create a Time Calculator in Visual Basic 2010

Create a VB application that lets the user enter a number of seconds and works as follows:

- there are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds.

- there are 3,600 seconds in an hour. If the number of seconds entered by the user is greater that or equal to 3,600, the program should display the number of hours in that many seconds

- there are 86,400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86,400, the program should display the number of days in that many seconds.

excellent tutorial.i know vb

excellent tutorial.i know vb basics.but dont have much idea about vb6.i found this tutorial much helpfull and easy to learn. thanks for giving this

how i enter data in database at run time in vb6

plz;
send this code soon.........

can you use 1 timer to get

can you use 1 timer to get things done at different times.
I wanna show 3 lines at different times with one timer

Timer

Hi
M very new to vb and m trying to create a small game. I have 4 picture box n i want the pic to b loaded in the first box as soon as i run it and the 2nd box shud display the pic after 1s and the 3rd 1 sec aftr the 2nd displays n so on. How can i use timer for tis???
Pls help me out with this.M using vb 2010.Expecting a rly sooner.
Thanks in advance.

Refresh timer for web page

Hi! I'm a total newb to VB but I'm trying to make a timer to refresh a web page and display it on a framless window. I've got the window part down but I cant figure out the timer module. Maybe a 60 minute refresh would work for it....

THANKS

I LIKE THIS PAGE. I KNEW NOTHING ABOUT TIMERS. NOE I'M AN EXPERT.
I LIKE TO THANK YOU FOR THIS FINE HELP.
NICE DAY

help me guys

how can i move the car .. moving car only .. thanks!

vb6

please give me a code of a program that if the user entered a wrong username and/or password, the message box will prompt "invalid entry, try again". And after three(3) attemps of wrong entry, message box "Program will end".....

thanks..!:)

The Code :)

This is just one idea:
1. cmdLogin is button for logging in,
2. txtUser is textbox in which user is typing username,
3. txtPass is textbox in which user is typing password.
4. example username is 'default' and example password is 'sesame'. You should change them in 7th and 8th line of code.

K, let's write the code:

Private Sub cmdLogin_Click()
Dim i
a$ = txtUser.Text
b$ = txtPass.Text
i = 0
Do
If a$ <> "default" Or b$ <>_ "sesame" Then
i = i +1
Msgbox "Invalid entry!",,"Error (" & i & ")"
Else
Msgbox "Correct username and password!",,"Correct"
goto thisisend
End If
Loop Until i = 3
Msgbox "Program will end",,"End"
End
thisisend:
End Sub

username and/or password Verification

The Code you are looking for depend on what Kind of Username and/or password you what to verify, that is to say if the Username and/or password is stored in a Database.

The example Codes below is for Username and/or password stored in a Database and if the Username and/or password dose not match with what is in the database it will bring up a message box.
I hope it will help.

Private Sub CmdLogin_Click()
Dim varbookmark As Variant
Dim password As String
Set db = OpenDatabase(App.Path + "\data\SYSTEM.mdb") 'Location of your Database
Set rs = db.OpenRecordset("users") 'Table in the Database where usernames and passwords are stored
If TxtUsername.Text = "" Then
MsgBox "ENTER USERNAME TO PROCEED!", vbCritical, "Error..."
TxtUsername.SetFocus
Exit Sub
End If
If TxtPassword.Text = "" Then
MsgBox "ENTER PASSWORD TO PROCEED!", vbCritical, "Error..."
TxtPassword.SetFocus
Exit Sub
End If
With rs
.MoveFirst
.Index = "user_name" 'Ensure it is the same will the index in the Database
varbookmark = .Bookmark
.Seek "=", (TxtUsername.Text) 'Searching the Database to see if such username exist
If .NoMatch Then
MsgBox "WRONG USERNAME", vbCritical, "FAILED"
.Bookmark = varbookmark
Exit Sub
End If
'Searching the Database to see if such password is for that username
If rs.RecordCount <> 0 Then
password = Trim(rs("password"))
End If

If password <> Trim(TxtPassword.Text) Then
MsgBox "Incorrect Password!", vbExclamation, "FAILED"
Else
Timer1.Enabled = True

End If
End With
End Sub

Need help

Hi... please help me...

I want to create an application where the application will close itself when the specified time has expired, can u help me please...

Warm Regards

help

Private Sub Timer1_Timer()
Dim a As Integer
a = 0
a = a + 1
If a Mod 2 = 0 Then
Label1.Visible = True
Else
Label1.Visible = False

End If

End Sub

The above coding does not work for me in vb.Actually i want to make it look like a blink in the form .plz help...

Move the Dim statement

Move the Dim statement outside of the subroutine. Right now, whenever Timer1_Timer is called, a is reinitialized and resets itself to 0.

YOU ROCKZZZ..!!!

YOU ROCKZZZ..!!!

Blinking label

Hi,

I assumed that your objective is to display a blinking label on your form. If that's the case please take a look on the codes below.

'======================================================================

Option Explicit

Private Sub Timer1_Timer()

With Me
If .Label1.Visible Then
.Label1.Visible = False
Else
.Label1.Visible = True
End If
End With

End Sub

'======================================================================

I have used Timer object instead of an integer variable because that is the most practical way if you only want to display a blinking label on your form.

I hope this can help.

Best regards,

Tobz

Dim a As Integer a = 0

Dim a As Integer
a = 0 <- each time the timer fire, your var a=0
a = a + 1 <- a=0+1=1 => in if clause a mod 2 = 1 mod 2
you should do this:
public a as integer
...
...
Private Sub Timer1_Timer()
a = a + 1
If a Mod 2 = 0 Then
Label1.Visible = True
Else
Label1.Visible = False
End If
End Sub

count down timer for each command button

Dear all,
Please help me, i need source code for my project. i need to start/run port bit for parallel port for running equipment as motor by timer. i have eight motors. for example i need to start the motor at 07:00 AM and stop at 9:00 AM. and the others have a timer too

port bit for parallel port

You can write to adress &H378 (888) = (LPT1)

Qbasic / GWBasic
out 888,n n = 0..255 , i assume you know how binary works
works with DOS (is very fast) and window < XP ! (I use W98SE, network, multitasking, USB..)

Just like in QBasic you can do the same in VisualBasic
VB6 is a litle more dificult becouse you need a DLL (< 10Kb) to be able to write to hardware adresses.
With that DLL it is the same as in QB.
Look at : http://www.aaroncake.net/electronics/vblpt.htm , more explanation
and : http://www.softcircuits.com/ , for the DLL

winXP (and up): I don't know yet, becouse XP is to protective.

From here it should be easy
Grtz, CTP

VB 6 Help me

I wanted to make my program not to close without my permission.What i did for it is entering codes as shown as bellow

Private Sub Form_Unload(Cancel As Integer)

If TxtPassWrd.text = "Password" then
end
else
Shell app.path & "\MyPrograme.exe"
end
end if

End Sub

when i try to close using Windows Task Manager > Application tab > right click on the program name and > End Task, it worked well but,

when i close it "End Process" it did not work.....................

***********************************************************

If anyone know how to code it preventing close a program even Windows Task Manager > End Process Please E-mail me or help me on this web..

Thank you,

Service?

Could this be done having an .exe file as a service? Won't windows try to restart a service if it has failed?

Just a thought...

hey i need help I got a

hey
i need help

I got a textbox and i have to know the source for get it sending a X number of messages. It shall start with a button or a DomainUpDown

In visual basic 2011

Simple Game

Please help about (label + timer with VB6)?
I have made ​​the task of running text in vb6, ..

as follows:
labels for as many as four labels, + timer

label 1 runs from left to right,
label 2 runs from right to left,
label 3 runs from top to bottom,
label 4 runs from the bottom up,

rules of the game:
-within 10 seconds pause label 1 label 2, 3, 4 path
-within 20 seconds pause labels 2 labels 1, 3, 4 path
within 30 seconds, 3 labeling pause labels 1, 2, 4 path
-within 40 seconds pause label 4 labels 1, 2, 3 streets

with a note:
-after label stop and re-direct the path forward from the earlier cessation of ...

vb

reply vb

i think its superb....

i think its superb....

images

Hello i am trying to make an image visible but only for a certain amount of time then it goes invisible again automatically but i can't seem to figure out how to do this.

research

....nice i have now an idea.. how to create this...

Record count to vb6

hi their every one
is their any way to count the records of recrodset i just connected my record using database & i have to display the records in label please it urgent..

logout and what you are doing stops

i have cybercafe and most times bowsers will logout their time while downloading something, and it is on my own expense. someone told me that, a cafe he visited, once one's time logout, what he is doing stops. i need your hlep on please, is it a software or what, 'cos i need it.... plz.

Colour light

In my vb form there are 3 circles that got in shapes control. Firstly i want to colour first circle as green, second as yellow and third as red. This should be as colour light. Always want to colour this colour light respectively. Please give codes to construct this programme.

Visual Basic 6 - Using Timer1, cmd.exe, and prgbar1 together

objective: show progress while a command is being exicuted through the cmd.exe or shell or some DOS command command.

showing progress for reading a text file is easy. I just get the record or line count and do a loop until the max count is reached.

how do I show the progress of a shell command? what interupt or event or property must I access?

I can see the cmd.exe icon in the task bar while i am executing a dos directory search.

what , how do i keep time of a shell command?

Waiting before Close...

So I'm creating a form in VB 2010 such that when you go to close the application, it wait 3 sec before it actually closes. I've looked all over for help with this and can only find how to display the timer or delay the timer from starting. If anyone has any tips, that would be awesome!!!!

I'm trying to program an

I'm trying to program an image to turn on after thirty seconds, to shut off three minutes after the image appears, and to appear again after thirty seconds.
I know what the code would be, however, I cannot enter more than 65 seconds for the interval property (the Visual Basic 6 Super Bible says the Interval property can range from 0 ~ 65 seconds). Does anyone know of a way to loop a timer to increase the amount of time enterable in the Interval Property?

TIME IN AND TIME OUT

and will also compute the days of absent ot hours and late .. please help me .. :) i need it asap .. thank you ..

TIME IN AND TIME OUT

Help Me Please.. :'(
im actually doing payroll system ..
i need a code in a Time in and Time out ..
My program goes like this .
First the user need to put his employee number on a textbox then search it automatically after he click the Search Button his employee name and position will appear on a textbox ..
then, he will click the time in button .. and it will be recorded .. supposedly that he click again the time in , this time it will not be recorded a msgbox will pop-up that he already log-in .. and in a time out button , it will also be recorded same with the time out if he supposedly click again ..

here is my own vb program,its

here is my own vb program,its really tear me down.could you guys help me?its connected with MS excel..
let's say if i type place like Newyork,then i wanna the price is 20
if i type the place like Hawaii,then i wanna the price is 30
and all places of all others will be 40.
so the program i own its like :
function price(place as variant)as integer
if place=newyork then price=20
elseif place=hawaii then price=30
else price=40
end if
end function

im not exactly sure what

im not exactly sure what you're trying to do...
put a textbox and button on your form, then in the button:

Dim intPrice As Integer

If TextBox1.Text = "New York" then
intPrice = 20
elseif TextBox1.Text = "Hawaii" then
intPrice = 30
else
intPrice = 40
End If

My dear frnd i'm new in vb bt

My dear frnd i'm new in vb bt wit wat u said u hv 2 declare ur d countrys txts as variables

automatic end time

I am developing a cybercafe system. I am having a problem in calculating the end time, it will display the end time automatically after the admin enter the duration for how many hours the client wanted to play.Let say, the start time is 12:00, then there is a combo box for admin to select how many hours the customer wanted to play and let say 2 hours. So the there will be a text box to display the end time.in this case, the end time will show you 14:00. so i have 2 text boxes and 1 combo box which is for the duration.please i really need your help.please send me the coding.

Done!

I hope this code will help you in a way:

Option Explicit
Dim I As Byte

Private Sub Form_Load()
Combo1.AddItem "Select hours..."
For I = 1 To 23
Combo1.AddItem I
Next
Text1.Text = Format(Now, "dd/mm/yy - hh:mm:ss")
Combo1.ListIndex = 0
End Sub

Private Sub Combo1_Click()
If Combo1.ListIndex > 0 Then
Text2.Text = Format(Now + CDate(Combo1.ListIndex & ":00:00"), "dd/mm/yy - hh:mm:ss")
Else
Text2.Text = Combo1.Text
End If
End Sub

Private Sub Text1_Change()
If Combo1.ListIndex > 0 Then _
Text2.Text = Format(Now + CDate(Combo1.ListIndex & ":00:00"), "dd/mm/yy - hh:mm:ss")
End Sub

Private Sub Timer1_Timer()
Text1.Text = Format(Now, "dd/mm/yy - hh:mm:ss")
End Sub

Create a new form with 2 text boxes, 1 combo box and a timer. Make timer's interval property to 1000 (1 sec) and paste the above code.

plese help me cinditinal propert of timer

I crete a login page in VB
OUR main aim to
enter the password in textbox if three time enter wrong password the textbox
will be disable for 90 second
please help me
as soon as
sadanand "MCA"
from Gurgaon HARYANA (BIHAR)

in general: Dim

in general:

Dim intLogInAttempts is Ingeter = 0

in a button:

If (your password/username is correct) then
(login)
else
intLogInAttempts = intLogInAttempts + 1
If intLogInAttempts = 3 then
intLogInAttempts = 0
Timer1.Enabled = True
(the log in button?).Enabled = False
End If
End If

in a timer:

(the log in button?).Enabled = True

i've only had about 12 weeks learing vb so i could be totally wrong

AT LEAST POST AN EXAMPLE OF

AT LEAST POST AN EXAMPLE OF YOU TRYING IT BEFORE ASKING FOR HANDOUTS.

RE: plese help me cinditinal propert of timer

Hi!

Please the code below.

Option Explicit

Private Const userName As String = "Admin"
Private Const password As String = "Pass"
Private noOfAttempts As Integer

Private Sub Command1_Click()

With Me
If .txtUsername.Text = userName And .txtPassword.Text = password Then
MsgBox "Access granted.", vbInformation, "Granted"
Rem To do
Else
MsgBox "Invalid username and/or password.", vbCritical, "Denied"
noOfAttempts = noOfAttempts + 1

If noOfAttempts = 3 Then
.txtUsername.Enabled = False
.txtPassword.Enabled = False
.Command1.Enabled = False
.tmrEnableTextboxes.Enabled = True
End If

End If
End With

End Sub

Private Sub tmrEnableTextboxes_Timer()

With Me
.tmrEnableTextboxes.Enabled = False
.txtUsername.Enabled = True
.txtPassword.Enabled = True
.Command1.Enabled = True
End With

End Sub

I hope this can help.

Best regards,
Tobz

use sleep.

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sleep 90000 '90s x 1000

Save Log time

Hi
Thanks for your codes on Internet cafe business
In VB 6.0 , I got an error while executing the below command.Is myTimeOutCon a function ?

rsLoged.open mySQLcode, myTimeOutCon, adOpenDynamic, adLockOptimistic

Timer continues after unload form

Hi,
I manage a VB6 application, having lots of forms. The forms are loaded using at central DialogManager-class.
One form has a timer-control, by default enabled. But by coincidence, I discovered that the Timer continues after unloading the form, putting a debug.print into the timer1_timer event. Even if I place a timer1.enabled = false in the form_queryunload, the timer is continuing (prooved by debug.print in the timer-event).
Why is the timer not flushed when I unload the form, and how can I be sure to kill the timer?
Thx
Joergen

Kill prg

Private Sub Form_Unload(Cancel As Integer)
End
End Sub

timer=true/false what is this??

when I type timer=, it shows true or false. for what does this true or false used???

it is used with

it is used with (.enabled).like this:- timer1.enabled=true/false..true is used to start the timer.and false is used to stop the timer.

when its true the timer will

when its true the timer will start to count, when it false the timer will stay at 0

youtube.com

hi
every time i write this for some reason it ses error

tmrTest.Enabled = True
please help

vb

i want a vb code for develop a vb program to stimulate the traffic signals, by using the following conditions.

I. Form consists of 3 signals Red,Green, & Yellow.
II.Form consists of one timer label, to display the time out signal.
III. While transorming the signal from Red to Green, Signal travel to Yellow.
IV. Time out for Red=180 sec.
V.. Time out for Yellow=60 sec.
VI. . Time out for green=120 sec.

Delay While Reading a File Line By Line

hello Guys
I am new to VB and am implementing a project that transmits a file from server to client. whilst displaying the contents of the file, i want to implement a delay (say 1sec delay) to be incorporated between the lines as it is displayed.

i have no idea how to do this.
any suggestions?
please help

thanks

to update database record at certain interval say every 13hours

i'm being given a program to design an application i have designed it to monitoring updated stocks and removes the stock as it's being sold.but the person want me to include into the database daily updated record to the database but i dont know how to go about it. pls i need code on how i can update the database with daily records.

my program

i want to have a code for time in / out of a employee.. in the form there's a textbox that will display the number of hours of the employee worked base on the time in.. vb 6.0 code pleasee..

vb

i want more coding of timer control in vb 6.0. This coding will contain more suffosticated to project or the software.
By using of timer controls we should be various effect to text .

i want some design of login screen.

answer pls..

how can i create a program that will display number 1-10 with delay without using a timer?

Without timer.

Create a delay routine, then print your number, call delay. It will return when delay is done and you can print your next number.

Private sub PrintNumber()
dim x as integer
x=0
do
x=x+1
print x
Delay 5 'delay 5 seconds
loop while x<11
end sub

Public Sub Delay(l As Single)
Dim w As Single
w = Timer + l
If w > 86399 Then ' If midnight
w = w - 86400
Do While Timer > 0
DoEvents
Loop
End If
Do While Timer < w
DoEvents
Loop
End Sub

HELP!

heyy we have to make a vb game for assessment and we would like to know how to move something from one point to another.. someone please reply ASAP
thanx

In a module called

In a module called declarations add

Public Button1X,Button1Y as integer

no on the for load you want to give ButtonX, and ButtonY a value these should the the start co-ordinates i.e. Button1X = 16 ButtonY=1, then you need the add 3 button events, Mousedown,MouseMove and MouseUp, these will control what the mouse is doing.

then add the following code

]
Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button41.MouseDown
              Dragging = True
            StartX = e.X
            StartY = e.Y
    End Sub
 
    Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button41.MouseMove
        If Dragging = True Then
            Button1.Left = (Button1.Left + e.X) - StartX
            Button1.Top = (Button1.Top + e.Y) - StartY
        End If
    End Sub
 
    Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
        Dragging = False
        Button1X = Button1.Location.X
        Button1Y = Button1.Location.Y
    End Sub
 
</Blockcode>
 
hope that helps a bit

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?

your question

what you have to do is first set a textbox i will just use text1 for the example, then you need a timer. In the timers code area put the code text1.text = text1.text - 1. put the number 60 in the textbox and set the interval speed on the timer to 1000 (this is the equivalent of 1 second in timers)

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

Timer

Thanks a lot for this code. ...... Thanks....thanks...

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

payroll

please help me on my time log codes in my payroll system

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

You would simply use an if statement to see what shape is visible and then set the correct timer to enabled as a result. Put this code in the Command button click event:
' Disable all timers and then enable the appropriate one
timer4.enabled = false
timer5.enabled = false
timer6.enabled = false

if shape1.visible = true then
  timer4.enabled = true
elseif shape2.visible = true then
  timer5.enabled = true
elseif shape3.visible = true then
  timer6.enabled = true
This should get you running. As you get it working would you please consider writing a quick tutorial teaching some of what you've learned. You can write it in Word or even as a text file and submit it through our Add Your Tutorial page. I think others would benefit from everything your learning and its always cool to get something published!

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

If you need it in seconds, adapt appropriately. Code for Timer Event :
  Text1.Text = dMinute & ":" & dSecond
  If dMinute = 0 And dSecond = 0 Then
    Text1.Text = "Finished."
    Exit Sub
  End If

  If dSecond = 0 Then
    dMinute = dMinute - 1
    dSecond = 60
  End If
  dSecond = dSecond - 1
End Sub
Where dSecond & dMinute are Private Integers in General Declarations. I set dMinute to the value 10 and dSecond to 0 in Form_Load.

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????

when you stop the timer it is

when you stop the timer it is already reset

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