VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



CPause (Class for pausing)

by Jan Botha (6 Submissions)
Category: VB function enhancement
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (6 Votes)

This is a class that you can use to make your app pause for a few hours/minutes/seconds or milliseconds. This will work even if midnight occurrs while pausing! (Thus, this is midnight-compliant, just like my CStopwatch class I submitted earlier.)

Inputs
Function pPause(ByVal Number as Single, Optional Byval Unit as iConstants) Number: the number of units, specified in Unit, that you want to pause Unit: Contains one of the Following: iMillisec ( = 3) iSeconds ( = 0) iMinutes ( = 1) iHours ( = 2) NOTE: If Unit is omitted, Unit will equal iSeconds
Side Effects
Unfortunately, if you want to see if this can pause through midnight, you'll have to set your system time. Nothing serious. :)

Rate CPause (Class for pausing)

'*************************************
'This goes into a class module
'Important: NAME THE MODULE "CPause"
'*************************************
Const iSecsInDay As Long = 86400
Enum iConstants
  iSeconds = 0
  iMinutes = 1
  iHours = 2
  iMilliSec = 3
End Enum
  
Public Function pPause(ByVal Number As Single, _
     Optional ByVal Unit As iConstants)
  Dim iStopTime, fakeTimer, sAfterMidnight, sBeforeMidnight
  If Unit = iSeconds Then
    Number = Number
   ElseIf Unit = iMinutes Then
    Number = Number * 60
   ElseIf Unit = iHours Then
    Number = Number * 3600
   ElseIf Unit = iMilliSec Then
    Number = Number / 1000
  End If
  fakeTimer = Timer
  iStopTime = fakeTimer + Number
  If iStopTime > iSecsInDay Then
    sAfterMidnight = iStopTime - iSecsInDay
    sBeforeMidnight = Number - sAfterMidnight
    fakeTimer = Timer
    While Timer < fakeTimer + sBeforeMidnight And Timer <> 0
      DoEvents
    Wend
    fakeTimer = Timer
    While Timer < fakeTimer + sAfterMidnight
      DoEvents
    Wend
   Else 'if pausing won't continue through midnight
    While Timer < iStopTime
      DoEvents
    Wend
  End If
End Function
'************************************
'Put the following in the Declaration
'section of a form
'************************************
Dim mytimer as CPause
'***************************************************
'Put the following into any Sub (eg. Command1_Click)
'***************************************************
Set mytimer = New CPause
'to pause for 10 seconds, use the following call
i = mytimer.pPause(10, iSeconds)
'**************************************************
'End of Code
'I welcome any comments bug reports or enhancements that can be made!
'

Download this snippet    Add to My Saved Code

CPause (Class for pausing) Comments

No comments have been posted about CPause (Class for pausing). Why not be the first to post a comment about CPause (Class for pausing).

Post your comment

Subject:
Message:
0/1000 characters