VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A Simple Long Delay Timer

by Scott Vermeersch (2 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (8 Votes)

A simple long delay timer. The VB Timer control is limited to 64k milli seconds, this short code extends that to near infinity in 6 lines of code. Heavily commented.

Assumes
Put a VB Timer control on a form. This assumes the control with a name of "Timer1".

Rate A Simple Long Delay Timer

Private Sub Timer1_Timer()
  
  'Set the interval of the timer.
  'Each time the timer event is called
  'subtract one from the tick.
  
  'Assuming 10000 interval with a 1440 tick,
  'this would give a delay of 4 hours.
  
  '10000 / 1000 = 10 *Milliseconds to Seconds
  '10 * 1440 = 14400 *Multiply by ticks
  '14400 / 60 = 240  *Seconds to minutes
  '240 / 60 = 4    *Minutes to hours
  
  'Allocate a static variable
  Static siTick As Integer
    
  'Check if variable greater then desired tick
  If siTick > 1440 Then
    
    '************ Do some code ************'
    
    'Start the ticker over
    siTick = 0
    
  'If not then add one to the tick
  Else
    siTick = siTick + 1
  End If
  
End Sub

Download this snippet    Add to My Saved Code

A Simple Long Delay Timer Comments

No comments have been posted about A Simple Long Delay Timer. Why not be the first to post a comment about A Simple Long Delay Timer.

Post your comment

Subject:
Message:
0/1000 characters