[VB6] Timer for > 1 minute

Discussion in 'Code Snippets and Tutorials' started by ricky92, Mar 1, 2007.

  1. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    If you used a timer control in VB6 you surely noticed that you can't set the interval to a number higher than 65.535. Here is the code to make a longlasting timer

    1. Create 2 labels, lblHours and lblMins

    2. Add these variables to the project:

    Code (Visual Basic):
    1. <div class="vb" id="{CB}" style="font-family: monospace;"><ol><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;"><span style="color: #b1b100;">Dim</span> intHours, intMinutes <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span></li></ol></div>
    3. Add this code to the timer:

    Code (Visual Basic):
    1. <div class="vb" id="{CB}" style="font-family: monospace;"><ol><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;">lblHours.<span style="color: #66cc66;">Caption</span> = intHours</li><li style="padding: 0 5px; background-color: #f9f9f9; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;">lblMins.<span style="color: #66cc66;">Caption</span> = intMinutes</li><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;">intMinutes = intMinutes - <span style="color: #cc66cc;">1</span></li><li style="padding: 0 5px; background-color: #f9f9f9; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;">&nbsp; &nbsp; <span style="color: #b1b100;">If</span> intHours > <span style="color: #cc66cc;">0</span> <span style="color: #b1b100;">Then</span></li><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">If</span> intMinutes < <span style="color: #cc66cc;">0</span> <span style="color: #b1b100;">Then</span></li><li style="padding: 0 5px; background-color: #f9f9f9; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; intHours = intHours - <span style="color: #cc66cc;">1</span></li><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; intMinutes = <span style="color: #cc66cc;">59</span></li><li style="padding: 0 5px; background-color: #f9f9f9; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span></li><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;">&nbsp; &nbsp; <span style="color: #b1b100;">ElseIf</span> intHours = <span style="color: #cc66cc;">0</span> <span style="color: #b1b100;">And</span> intMinutes < <span style="color: #cc66cc;">0</span> <span style="color: #b1b100;">Then</span></li><li style="padding: 0 5px; background-color: #f9f9f9; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tmrSecs.<span style="color: #66cc66;">Enabled</span> = <span style="color: #b1b100;">False</span></li><li style="padding: 0 5px; background-color: #fff; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">'code to execute at the end of the timer</span></li><li style="padding: 0 5px; background-color: #f9f9f9; line-height: 16px; border-bottom: 1px solid #efefef; border-left: 1px solid #999;">&nbsp; &nbsp; <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span></li></ol></div>
     
  2. the_skip

    the_skip Level IV

    Joined:
    Dec 25, 2006
    Messages:
    2,354
    Likes Received:
    1
    Location:
    Indiana
    thanks I will use this in my usershop ab
    Would this update itself if I put it in my form load procedure
     
  3. Anonymous

    Anonymous Guest

    nice work ricky!
     
  4. Xiaoset

    Xiaoset Level III

    Joined:
    Feb 23, 2007
    Messages:
    421
    Likes Received:
    0
    Location:
    Canada
    Thanks! +rep