Timer Function in VB.NET

remya1000

Well-known member
Joined
Mar 29, 2007
Messages
122
Programming Experience
Beginner
I'm using VB.NET.
in VB6 we have a function called Timer, which returns a Single value that represents the number of seconds that have elapsed since midnight.

for eg:
lngStartTimer = Timer

but in VB.NET, while i try to use this timer function, error occurs. i'm not able to use this Timer function in VB.NET. but i need to take time as we take time using Timer(no: of seconds since midnight).

anyone have anyidea, how to use timer function in VB.NET. please let me know. and if you can provide any eg: that will be great help for me.

thanks in advance.
 
Example:-
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Call Function()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 3000
Timer1.Enabled = True
End Sub

------------------------------------------------------------------------
Here Call Function() contains the code which you want to call.
(Timer1.Interval = 3000) is the time interval 1000ms = 1sec, hee it is 3sec
(Timer1.Enabled = True) enables the timer.
You should also go to properties of timer and check settings and make changes there also if necessary.


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Call Function()
End Sub

This code is to be written by putting a timer on form load and entering in it.

And Timer enabled code is to be written on form load.
Try it it should work. I had done it in same way. Ask if any more difficulties.
:)
 
Last edited:
You can calculate it easily with Date and TimeSpan:
VB.NET:
Dim SecondsSinceMidnight As Double = Date.Now.Subtract(Date.Today).TotalSeconds
but I don't understand your need to know this information, so I wonder what is it you are trying to do?
 
i'm using a Caller ID Utility program, to store all incoming, outgoing, non answered calls to database. and it will save the line number, phone number, name, time, timeonhook, timeoffhook etc. so for soem calculation i need to take time value in seconds that have elapsed midnight.

and by using your code its working... now its returns a Single value that represents the number of seconds that have elapsed since midnight. i'm getting values in seconds.

VB.NET:
Dim SecondsSinceMidnight As Double = Date.Now.Subtract(Date.Today).TotalSeconds

thanks a lot for this help.
 
Back
Top