- Home
·
- Miscellaneous
·
- Calls any procedure on any object, however often you like for a given amount of time. No timer cont
Calls any procedure on any object, however often you like for a given amount of time. No timer cont
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
(1(1 Vote))
'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
Calls any procedure on any object, however often you like for a given amount of time. No timer cont Comments
No comments yet — be the first to post one!
Post a Comment