Results 1 to 4 of 4

Thread: Performing an action

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Posts
    79

    Lightbulb

    Does anyone know how I can get my program to perform an action every 30 minutes. This amount is too big for a timer. I have tried putting it into a loop checking to see if the oldtime + 30 mins equals new time, but it stops responding properly

    Thanks a lot


    Mark

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    You can use a timer. You will also need a variable.

    Code:
    Timer1.Interval = ??  'whatever you chose.
    
    Private Sub Timer1_Timer()
        Static iTime As long
    
        iTime = iTime + Timer1.Interval
        
        If iTime >= 1800000  Then    '30 minutes
          'do something.
          iTime = 0
        End If
    
    End Sub
    Iain, thats with an i by the way!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Posts
    79
    Thanks. Why didn't I think of that myself?

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    SetTimer API

    I think this is better, because it does not need any OCX control.
    Code:
    Option Explicit
    Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    Private 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)
        MsgBox "30 minutes is over."
    End Sub
    
    Private Sub Form_Load()
        SetTimer Form1.hwnd, 0, 1800000, AddressOf TimerProc
    End Sub
    
    Private Sub Form_Unload()
        KillTimer Form1.hwnd, 0
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width