Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Timer control's interval more than 65,535 milliseconds

Posted on 2003-10-26
10
Medium Priority
?
1,411 Views
Last Modified: 2008-02-01
I want to do somethiing repeatly ... I plan to use a timer control in the VB. However, the maximum, 65,535 milliseconds, is equivalent to just over 1 minute. That's mean I can do something repeatly within 1 mins. Would somebody tells me how can I set the interval more than 1 mins ?
0
Comment
Question by:mikekwok
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +4
10 Comments
 
LVL 3

Expert Comment

by:pg_india
ID: 9625253
u can do sumthg like this

declare a variable a
in form load a=0
in timer event
if a<10 then
   a = a+1
else
  a = 0
  ' what u want to do
end if

in this way ur timer will behave 10*timer inbterval time

do post if any doubt
0
 
LVL 7

Expert Comment

by:_agj_
ID: 9625271
Something like:

sub timer1_timer()

static tim_count as integer

if tim_Count = 10 then
    tim_count = 0
    timer1.interval = 0
else
   tim_count = tim_count + 1
end if

end sub
0
 

Author Comment

by:mikekwok
ID: 9625366
Sorry The timer is not accurate enough ..... After I have set the value to a < 1000 . Would somebody pls help me ? Thanks.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:mikekwok
ID: 9625368
I want to use a timer that can input the time interval more than 1 hour.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9625424
You can use the wonderful function called DateDiff.

Here is a sample app I wrote to show how it works quite nicely.  Create a new project and place three labels and a timer control on it.  The first label will show the current time.  The second label will show total elapsed time since the program started.  The third label will show elapsed time since the last "event".  

This type of scheme is not good for benchmarking apps in the millisecond range, but it works great for longer durations where that kind of accuracy doesn't matter.

The code is pretty self explanatory.  Hope it helps...and here it is:

Dim eventInterval As Long
Dim lastEventTime As Date
Dim initialTime As Date

Private Sub Form_Load()
    ' Set this value to the number of seconds you want inbetween your events
    ' It is a Long, so the max value is...
    '  max val: 2,147,483,647 seconds
    ' or approx 35,791,394 minutes
    ' or approx 596,523 hours
    ' or approx 24,855 days
    ' or approx 68.10 years
    eventInterval = 90
   
    initialTime = Now()
    lastEventTime = initialTime
    Timer1.Interval = 250
End Sub

Private Sub Timer1_Timer()
    Dim curTime As Date
    Dim elapsed As Long
   
    Dim elapsedSeconds As Long
    Dim elapsedHours As Long
    Dim elapsedMinutes As Long
    Dim elapsedString As String
   
    curTime = Now()
   
    ' update current time
    Label1.Caption = Format(curTime, "Long Time")
       
    ' update total elapsed time
    elapsed = DateDiff("s", initialTime, curTime)
    ' conversions to secs, mins and hrs...
    elapsedSeconds = elapsed
    elapsedHours = elapsedSeconds \ 3600
    elapsedSeconds = elapsedSeconds - (elapsedHours * 3600)
    elapsedMinutes = elapsedSeconds \ 60
    elapsedSeconds = elapsedSeconds - (elapsedMinutes * 60)
    elapsedString = Format(elapsedHours, "00") & ":" & _
        Format(elapsedMinutes, "00") & ":" & Format(elapsedSeconds, "00")
    Label2.Caption = elapsedString
   
    ' update elapsed time since last event
    elapsed = DateDiff("s", lastEventTime, curTime)
    ' conversions to secs, mins and hrs...
    elapsedSeconds = elapsed
    elapsedHours = elapsedSeconds \ 3600
    elapsedSeconds = elapsedSeconds - (elapsedHours * 3600)
    elapsedMinutes = elapsedSeconds \ 60
    elapsedSeconds = elapsedSeconds - (elapsedMinutes * 60)
    elapsedString = Format(elapsedHours, "00") & ":" & _
        Format(elapsedMinutes, "00") & ":" & Format(elapsedSeconds, "00")
    Label3.Caption = elapsedString
    If elapsed >= eventInterval Then
        lastEventTime = curTime
        ' place a call to your "event" subroutine here
        '
        ' <-----------------------
        '
        '
    End If
End Sub
 
0
 
LVL 3

Expert Comment

by:pg_india
ID: 9625519
Instead of taking the datediff in sec you can take it in mins or hour depending on the interval that ur looking at.....

0
 
LVL 5

Accepted Solution

by:
Cimperiali earned 200 total points
ID: 9626465
Use api timers.
Option Explicit

'In a module
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
   Debug.Print "timer trigged!"
End Sub



'In a form
Option Explicit

Private Sub CmdStop_Click()
    On Error Resume Next
    'Kill our API-timer
    KillTimer Me.hwnd, 0
End Sub


Private Sub Form_Load()
    Dim mSeconds As String
    mSeconds = InputBox("enter number of millisecond fro timer to trig (note: 3600000=1 hour")
    If IsNumeric(mSeconds) Then
          SetTimer Me.hwnd, 0, CLng(mSeconds), AddressOf TimerProc
    End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
    On Error Resume Next
    'Kill our API-timer
    KillTimer Me.hwnd, 0
   
End Sub


0
 
LVL 9

Expert Comment

by:Dang123
ID: 9627767
0
 

Expert Comment

by:vbwizardxxx
ID: 9655002
A simple way of doing what you want is this:

Private Sub Pause(Duration As Long)
Dim Current As Long
    Current = Timer

Do Until Timer - Current >= Duration
DoEvents
Loop
End Sub

Private Sub Form_Load()
' will pause x milliseconds
Pause(x)
End Sub
0
 

Expert Comment

by:vbwizardxxx
ID: 9655013
sorry, Pause(x) will pause x seconds :P
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question