Results 1 to 8 of 8

Thread: VB6 - how terminate an infinite loop after close the window?

  1. #1

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

    VB6 - how terminate an infinite loop after close the window?

    when we close the window, when we have an infinite loop, the window is closed, but the program stays on memory and the execution isn't terminated.
    when we close the window, when we have an infinite loop, how can we terminate that loop?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: VB6 - how terminate an infinite loop after close the window?

    Code:
    Private mClosed As Boolean
    
    Private Sub Form_Load()
        Me.Show
        Do
            DoEvents
            If mClosed Then Exit Do
        Loop
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        mClosed = True
    End Sub

  3. #3

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

    Re: VB6 - how terminate an infinite loop after close the window?

    the rate was for be 'thank you so much'... sorry only be 'tk'...
    thank you so much for all...
    i was severy confused on what event was activated when we close the window... so it's 'unload' event.
    i belive the manual connects the close window button to 'Terminate' event.. but it's wrong.
    yes some VB6 events have problems... like get\lost focus window events.
    thank you so much for all
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: VB6 - how terminate an infinite loop after close the window?

    There is also another event that is the QueryUnload event.

    Load/QueryUnload/Unload events are related to the GUI (graphical user interface) elements, ie: the window - the form.

    Initialize/Terminate events are related to the code module (to module level variables, their states)

  5. #5
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: VB6 - how terminate an infinite loop after close the window?

    if you are using DirectX remember to have double loop and error exit-codes.
    I use:

    Code:
    Do While Running = 0
    Do While Running = 0
    - code -
    DoEvents (or PeekMessage)
    Loop
    - code if error, where u could re-enter the loop or exit it -
    Loop
    - termination procedures (unload, hooks etc)
    - end
    so while Running is 0, it will continue looping
    running can be used for error-coding or if the user clicking on any exit button.

  6. #6

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

    Re: VB6 - how terminate an infinite loop after close the window?

    i'm sorry, but why 2 loops?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: VB6 - how terminate an infinite loop after close the window?

    I wrote it: if u use DirectX.
    if you have your code running, and u exit to the login screen, and u enter again, all assets will be lost, and u need to reload the assets again or it will crash.
    I have a On Error GoTo error, in my rendering function, and if theres an error it will exit the loop.
    there I will reload the assets and re-enter the loop.

  8. #8

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

    Re: VB6 - how terminate an infinite loop after close the window?

    now i get it
    thanks for all.. thank you
    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