Results 1 to 10 of 10

Thread: [VB6] - instances privates

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    [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...)?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: [VB6] - instances privates

    Quote Originally Posted by Nightwalker83 View Post
    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?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: [VB6] - instances privates

    Quote Originally Posted by LaVolpe View Post
    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?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: [VB6] - instances privates

    Quote Originally Posted by LaVolpe View Post
    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?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    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?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] - instances privates

    Quote Originally Posted by joaquim View Post
    ...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).
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: [VB6] - instances privates

    Quote Originally Posted by LaVolpe View Post
    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.
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width