i have 1 sub in my control(with do..loop).
then i put 2 instances in form.
when 1 instance is using that sub, the 2nd instance can't use it.. why these beavoir?
why that sub isn't private too(like say 1 instance, 1 sub... 2 instances, 2 sub's...)?
Printable View
i have 1 sub in my control(with do..loop).
then i put 2 instances in form.
when 1 instance is using that sub, the 2nd instance can't use it.. why these beavoir?
why that sub isn't private too(like say 1 instance, 1 sub... 2 instances, 2 sub's...)?
I don't understand what you mean perhaps if you post your code it with help explain the problem.
heres the sub:
what is the problem: you can use this code in control instance, but if this sub is used the other instance can't use it and i don't understand why:(Code:Private Sub WaitMs() 'wait a given number of milliseconds
Dim t As Currency
Dim f As Currency
Dim e As Currency
Dim i As Long
Dim a As Boolean
Do
f = 0
t = 0
e = 0
QueryPerformanceFrequency f 'get number of counts/second
t = f * lngMS / 1000# 'multiply f by number of seconds to get number of counts to wait
QueryPerformanceCounter e 'get current count number
e = e + t 'add number of counts to wait to current count
Do
QueryPerformanceCounter t
If t > e Then
Call PostMessage(lngHwnd, WM_KEYDOWN, 1000, 0) ' this line indicates an action
API_DoEvents
If blnTimer = False Then
Exit Sub
End If
Exit Do
End If
Loop
API_DoEvents
If blnTimer = False Then
Exit Do
End If
Loop
End Sub
i know that is something about the do..loop, but i can't avoid it:(
but why this sub can't be used by it's own instance?
VB6 isn't multithreaded.
This portion of your code is probably holding you up
Until t > e, your loop will not allow other code to be run. Only when t > e and you either exit the procedure or execute DoEvents does other code run. I think you'll want a DoEvents for every nth loop iteration?Code:Do
QueryPerformanceCounter t
If t > e Then
...
API_DoEvents
...
End If
Loop
Anyway, just an ideaCode:Dim iCounter as Integer
...
Do
QueryPerformanceCounter t
If t > e Then
...
API_DoEvents
...
ElseIf iCounter = 10 Then
iCounter = 0
DoEvents
Else
iCounter = iCounter + 1
End If
Loop
Yes. However, calling DoEvents (or your api_doevents) every loop iteration is probably overkill. The more DoEvents that get executed, less accurate your WaitMs function will be, because other code will be running too. Play with iCount and maybe increase it, by 10's or 100's, or even decrease to see any differences
this sub can resolve my problem:
from here: http://pt.w3support.net/index.php?db=so&id=155517Code:' at the top:
Declare Function GetQueueStatus Lib "user32" (ByVal qsFlags As Long) As Long
' then call this instead of DoEvents:
Sub DoEventsIfNecessary()
If GetQueueStatus(255) <> 0 Then DoEvents
End Sub
can resolve my problem?
I doubt it. That API basically tests the message queue. Without breaking up your loop with a DoEvents, no other code will be allowed to run while your code is looping. In order to allow other instances of your control to enter their own loops & run their own code, DoEvents (or something similar) is probably the answer. Any code that is executing has nothing to do directly with the message queue. Of course a message may be processed by the queue that activates code (timer for example) or your code may insert messages into the queue (PostMessage for example).
stills working 1 timer at a time:(
instead use the do_events can i use 1 api function for tell the program for work with next "work"\process\event?Code:Private Sub WaitMs(ByVal lngMS As Long) 'wait a given number of milliseconds
Dim t As Currency
Dim f As Currency
Dim e As Currency
Do
f = 0
t = 0
e = 0
QueryPerformanceFrequency f 'get number of counts/second
t = f * lngMS / 1000# 'multiply f by number of seconds to get number of counts to wait
QueryPerformanceCounter e 'get current count number
e = e + t 'add number of counts to wait to current count
Do
QueryPerformanceCounter t
If t > e Then
RaiseEvent Timer
If blnEnabled = False Then
Exit Sub
End If
Exit Do
End If
DoEvents
Loop
If blnEnabled = False Then
Exit Do
End If
Loop
End Sub