|
-
Sep 26th, 2011, 03:44 PM
#1
Thread Starter
PowerPoster
[VB6] - instances privates
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...)?
-
Sep 26th, 2011, 11:29 PM
#2
Re: [VB6] - instances privates
I don't understand what you mean perhaps if you post your code it with help explain the problem.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Sep 27th, 2011, 02:22 PM
#3
Thread Starter
PowerPoster
Re: [VB6] - instances privates
 Originally Posted by Nightwalker83
I don't understand what you mean perhaps if you post your code it with help explain the problem.
heres the sub:
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
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
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?
-
Sep 27th, 2011, 02:51 PM
#4
Re: [VB6] - instances privates
VB6 isn't multithreaded.
This portion of your code is probably holding you up
Code:
Do
QueryPerformanceCounter t
If t > e Then
...
API_DoEvents
...
End If
Loop
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:
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
Anyway, just an idea
-
Sep 27th, 2011, 03:04 PM
#5
Thread Starter
PowerPoster
Re: [VB6] - instances privates
 Originally Posted by LaVolpe
VB6 isn't multithreaded.
This portion of your code is probably holding you up
Code:
Do
QueryPerformanceCounter t
If t > e Then
...
API_DoEvents
...
End If
Loop
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:
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
Anyway, just an idea
like:
Code:
Do
QueryPerformanceCounter t
If t > e Then
...
...
End If
api_doevents
Loop
right?
-
Sep 27th, 2011, 03:11 PM
#6
Re: [VB6] - instances privates
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
-
Sep 27th, 2011, 03:16 PM
#7
Thread Starter
PowerPoster
Re: [VB6] - instances privates
 Originally Posted by LaVolpe
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
if is a problem is there another keyword\sub\function that i can use instead do_events or api_doevents?
-
Sep 27th, 2011, 03:47 PM
#8
Thread Starter
PowerPoster
Re: [VB6] - instances privates
this sub can resolve my problem:
Code:
' 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
from here: http://pt.w3support.net/index.php?db=so&id=155517
can resolve my problem?
-
Sep 27th, 2011, 05:41 PM
#9
Re: [VB6] - instances privates
 Originally Posted by joaquim
...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).
-
Sep 28th, 2011, 02:13 PM
#10
Thread Starter
PowerPoster
Re: [VB6] - instances privates
 Originally Posted by LaVolpe
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
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
instead use the do_events can i use 1 api function for tell the program for work with next "work"\process\event?
Last edited by joaquim; Sep 28th, 2011 at 02:18 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|