-
June 8th, 2011, 11:00 PM
#1
How To set timer in VB6
I want to use the timer function to get latest information from database
if it's more than 1 minute then the function will get the latest data and update the text box.
Pls guide me how to do this.
Thanks!
-
June 9th, 2011, 01:03 AM
#2
Re: How To set timer in VB6
Timer interval is in milliseconds. To have code execute 1 time each minute place a timer on your form, set the timer interval to 60,000, set the enabled property to true and place a call to your code in the timer tick event.
Always use [code][/code] tags when posting code.
-
June 9th, 2011, 03:01 AM
#3
Re: How To set timer in VB6
Depending on the amount of processing the Timer event must do, setting it for each minute can cause some really sluggish ( slow ) applications, be careful if that is the case
-
June 9th, 2011, 03:27 AM
#4
Re: How To set timer in VB6
My interval should be between 5-10 min
-
June 9th, 2011, 10:15 AM
#5
Re: How To set timer in VB6
Best to use a ONE SECOND (or so) timer, and count the CLICKS
It counts UP for a minute...
Code:
Option Explicit
' Add a Timer control to your project. It will be Timer1
' It looks like a stop watch in the IDE.
Dim OldTime As Date
Dim newTime As Date
Dim diff As Date
Private Sub Form_Load()
OldTime = Time
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Static x As Long
Static zz$, ss$
x = x + 1
newTime = Time
diff = DateDiff("s", OldTime, newTime)
Form1.Caption = (diff \ 3600) & ":" & Format((diff \ 60 Mod 60), "00") & ":" & _
Format((diff - ((diff \ 60) * 60)), "00")
' Debug.Print (diff \ 3600) & ":" & Format((diff \ 60 Mod 60), "00") & ":" & _
Format((diff - ((diff \ 60) * 60)), "00")
If newTime = DateAdd("s", 360, OldTime) Then ' Add 360 seconds
Timer1.Enabled = False
' You time is UP! Do something!
Beep
End If
End Sub
Note to self: Reinstall VB6... Knew I forgot something...
-
June 9th, 2011, 10:41 AM
#6
Re: How To set timer in VB6
I would disagree, True it will fire every minute but it is also firing 59 times in between and doing some processing each time. This is not a big deal but getting in a habit of writing such code will result in programs running slower than they should.
If you need it to fire every 5 to 10 minutes I would set the interval to 1 minute and use a counter to see how many minutes have elapsed using a static var with a counter as is the case in the example above with X though X is not used in the code just as a wasted process.
In your timer routine
Code:
Static x As Integer
x=x+1
If X> 5 then
X=0
'Do your processing
End IF
Last edited by DataMiser; June 9th, 2011 at 10:46 AM.
Always use [code][/code] tags when posting code.
-
May 23rd, 2019, 07:58 AM
#7
Re: How To set timer in VB6
Originally Posted by dglienna
Best to use a ONE SECOND (or so) timer, and count the CLICKS
It counts UP for a minute...
Code:
Option Explicit
' Add a Timer control to your project. It will be Timer1
' It looks like a stop watch in the IDE.
Dim OldTime As Date
Dim newTime As Date
Dim diff As Date
Private Sub Form_Load()
OldTime = Time
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Static x As Long
Static zz$, ss$
x = x + 1
newTime = Time
diff = DateDiff("s", OldTime, newTime)
Form1.Caption = (diff \ 3600) & ":" & Format((diff \ 60 Mod 60), "00") & ":" & _
Format((diff - ((diff \ 60) * 60)), "00")
' Debug.Print (diff \ 3600) & ":" & Format((diff \ 60 Mod 60), "00") & ":" & _
Format((diff - ((diff \ 60) * 60)), "00")
If newTime = DateAdd("s", 360, OldTime) Then ' Add 360 seconds
Timer1.Enabled = False
' You time is UP! Do something!
Beep
End If
End Sub
Note to self: Reinstall VB6... Knew I forgot something...
Hi, can you help me to modify your this code to get the timing information in Milliseconds as well please?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|