VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Calls any procedure on any object, however often you like for a given amount of time. No timer cont

by VB-Kung-Fu (19 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 9th November 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Calls any procedure on any object, however often you like for a given amount of time. No timer control, no API, just pure magic :)

API Declarations


Public Type RepeatOperationArgs
'how long to keep repeating the operation
Seconds As Long
'how often to repeat the operation
Interval As Long
'object that has the operation
Obj As Object
'name of operation to perform
OpName As String
'operation type
OpType As VbCallType
'arguments to pass to operation
Args(1 To 1) As Variant
End Type

Rate Calls any procedure on any object, however often you like for a given amount of time. No timer cont



'and call it from anywhere.

'-------------------------------------------------------------------
Public Sub RepeatOperation(OpArgs As RepeatOperationArgs)
Dim n As Long

n = Timer + OpArgs.Seconds

Do While Timer < n
    If (Timer Mod OpArgs.Interval) = 0 Then
        With OpArgs
            CallByName .Obj, .OpName, .OpType, .Args(1)
        End With
    End If
    DoEvents: DoEvents: DoEvents
Loop
End Sub

'----------------------------------------
'paste the code below onto a form to try
'out the above subroutine.
Public Sub ShowMsg(msg As Variant)
MsgBox msg
End Sub

Private Sub Form_paint()
Dim arg As RepeatOperationArgs

With arg
    'call ShowMsg
    .OpName = "ShowMsg"
    
    'which is a method
    .OpType = VbMethod
    
    'on this form,
    Set .Obj = Me
    
    'that takes this argument.
    .Args(1) = "Hello there!"
        
    'Call it every 2 seconds
    .Interval = 2
    
    'for 10 seconds.
    .Seconds = 10
          
End With

Call RepeatOperation(arg)

End Sub

Download this snippet    Add to My Saved Code

Calls any procedure on any object, however often you like for a given amount of time. No timer cont Comments

No comments have been posted about Calls any procedure on any object, however often you like for a given amount of time. No timer cont. Why not be the first to post a comment about Calls any procedure on any object, however often you like for a given amount of time. No timer cont.

Post your comment

Subject:
Message:
0/1000 characters