Page 1 of 2 12 LastLast
Results 1 to 40 of 53

Thread: What is the code to quit my program I created?

  1. #1

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    Question What is the code to quit my program I created?

    I just finished building my application that I built in VB6. I have an Exit button on the main form that unloads the main form. I have Unload me code already. What is the line of code that ends the running of my code?
    Last edited by Avatarp; Oct 1st, 2002 at 03:42 PM.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    To unload the form you are currently working with, you would use

    Unload Me

    and generally people like to use this code in the form's unload event to clean up after multiple forms...
    VB Code:
    1. Dim frm As Form
    2.  
    3.     For Each frm In Forms
    4.         Unload frm
    5.         Set frm = Nothing
    6.     Next
    7.  
    8.     End

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    not sure what you mean

    if u mean unload the form just use

    Unload Me
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  4. #4

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    I've done that

    I have done that already. But VB6 still stays in run mode. So what else do I need to end my run mode?

  5. #5
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    try this

    Unload Me
    End


    usually ppl dont use End, but just try it after the unload me
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  6. #6
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Re: I've done that

    Originally posted by Avatarp
    I have done that already. But VB6 still stays in run mode. So what else do I need to end my run mode?
    Read above and you will see the answer has been already posted...

    VB Code:
    1. Dim frm As Form
    2.  
    3.     For Each frm In Forms
    4.         Unload frm
    5.         Set frm = Nothing
    6.     Next
    7.  
    8.     End
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  7. #7

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    Thanks

    End works...LOL that was easy

  8. #8
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Re: Thanks

    Originally posted by Avatarp
    End works...LOL that was easy
    END

    This is the most unprofessional, unreliable way of exiting a program...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  9. #9
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    Well....

    i told him to try Unload Me first, but didnt seem to work for him so i said End
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  10. #10
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    So now we know somethin in the program isn't ending properly... an unreleased resource...

  11. #11
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by nemaroller
    So now we know somethin in the program isn't ending properly... an unreleased resource...
    Huh ?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  12. #12
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    Well...

    i think hes saying, since Unload Me isnt working... part of the program is still running .....right?
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  13. #13
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    yes

  14. #14
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    And using this code doesn't work for you?

    VB Code:
    1. Dim frm As Form
    2.  
    3.     For Each frm In Forms
    4.         Unload frm
    5.         Set frm = Nothing
    6.     Next
    7.  
    8.     End

    This is how I end all my apps...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  15. #15
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    If your have more than 1 form still loaded in your project, then you need to unload that as well.
    Don't Rate my posts.

  16. #16
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    The code I posted will unload all the forms !!!
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  17. #17
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    well....

    if his app still wasnt ending And he placed teh code in the right place, something was still running

    just not sure what tho
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  18. #18
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    Re: Well

    Originally posted by James Stanich
    The code I posted will unload all the forms !!!
    Yeah.. or you could just do
    Unload Form1
    Unload Form2.

    Alot less code if he only has 2 forms.
    Don't Rate my posts.

  19. #19
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    If this code is place in any form in the project, all forms and form levels variables will be destroyed... this would in turn release all memory being consumed, and close the application... I do not understand the argument here...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  20. #20
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    James is correct. His code will unload all forms and clear up the memory they take, but if there are any loops running, it won't stop them. You will need to stop the loop before you can exit the program and release all the resources it's taking.
    <removed by admin>

  21. #21
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Loops running at time of close? You mean a crash in the loop?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  22. #22
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    No, I mean if you put in a loop somewhere that is running, say you put this on a form, then try to exit the program using your code, it will close the form, but it will still be in memory:
    VB Code:
    1. For I = 0 to 500000000
    2.   Debug.Print I
    3.   DoEvents
    4. Next
    <removed by admin>

  23. #23
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    But wouldn't "i" be terminated, thus terminating the loop?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  24. #24
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Nope. Try it. I just did, and it just keeps printing to the debug window, although the app has closed.
    <removed by admin>

  25. #25
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by MidgetsBro
    Nope. Try it. I just did, and it just keeps printing to the debug window, although the app has closed.
    That's amazing. The varaibles should be destroyed but are not. Scary thought....
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  26. #26
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Because you are just setting the forms to nothing, you aren't setting any variables to nothing. You would have to loop through all your variables you declared earlier in the program and set each one to nothing, if that's even possible.
    <removed by admin>

  27. #27
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by MidgetsBro
    Because you are just setting the forms to nothing, you aren't setting any variables to nothing. You would have to loop through all your variables you declared earlier in the program and set each one to nothing, if that's even possible.
    By setting the form = nothing, I was lead to belive that the form level variables were alos destroyed. Was I mislead?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  28. #28
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    ahh

    well what would be so bad about using End in this situation?
    or couldt it possibly cause an error
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  29. #29
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Either that, or the programmers of VB intended for that to happen, but then they never implemented it into the language...

    The best way to do this is to check a "Quitting" variable in each loop that might run for any length of time that is user noticable, an if it's set to true in the form_QueryUnload event, then in the loops you can exit the loop if the variable is set to true.
    VB Code:
    1. 'General Declares
    2. Dim Quitting As Boolean
    3. Dim LoopQuitSuccessful As Boolean
    4.  
    5. Private Sub EndlessLoop()
    6. Do
    7.   Debug.Print "Doing Nothing"
    8.   If Quitting Then
    9.     LoopQuitSuccessful = True
    10.     Exit Loop
    11.   End If
    12.   DoEvents
    13. Loop
    14. End Sub
    15.  
    16. Private Sub Form_QueryUnload(Cancel As Integer)
    17. Quitting = True
    18. Do Until LoopQuitSuccessful
    19.   DoEvents
    20. Loop
    21. End Sub
    Last edited by MidgetsBro; Oct 1st, 2002 at 10:37 PM.
    <removed by admin>

  30. #30
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    End won't cause an error, but it doesn't free up memory either. It just quits the process, but leaves everything it used, instead of cleaning it up. If the user ends the program like this numerous times in a single session (like if they don't shut their computer down often) then they will run out of resources and be forced to shut down or restart the computer.
    <removed by admin>

  31. #31
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Since we are beating this to death here, what about global variables, is there a proper way of releasing that memory?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  32. #32
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Not sure about globals, as I don't use them often, but if you don't set them to nothing, then I assume they will stay in memory as well... *ponders*
    <removed by admin>

  33. #33
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    ooook

    oh ok lol
    end.Bad = True
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  34. #34
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Re: ooook

    Originally posted by ice_531
    oh ok lol
    end.Bad = True
    At least someone learned something in all this babble...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  35. #35
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152
    lol
    i learn something new every day on this forum
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  36. #36
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    Re: Re: ooook

    Originally posted by James Stanich
    At least someone learned something in all this babble...
    I learnt something as well. Don't listen to myself.
    Don't Rate my posts.

  37. #37
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    Originally posted by MidgetsBro
    End won't cause an error, but it doesn't free up memory either. It just quits the process, but leaves everything it used, instead of cleaning it up. If the user ends the program like this numerous times in a single session (like if they don't shut their computer down often) then they will run out of resources and be forced to shut down or restart the computer.
    DAMMIT....

    No wonder my App keeps freezing me up..

    THANKS DOOD!
    Wayne

  38. #38
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    Also,

    i put the code above (for each frm) in my "Unload" statement?
    Wayne

  39. #39
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    What i usually do is create a global sub in a module which when I want to exit any form I call like this

    VB Code:
    1. Call GOODEXIT

    Then the subroutine

    VB Code:
    1. Sub GOODEXIT()
    2.  
    3. Dim frm As Form
    4.  
    5.     For Each frm In Forms
    6.         Unload frm
    7.         Set frm = Nothing
    8.     Next
    9.  
    10.     End
    11.  
    12. End Sub
    Last edited by James Stanich; Oct 2nd, 2002 at 09:33 AM.
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  40. #40
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    dont u need

    VB Code:
    1. Public
    at the top, and

    VB Code:
    1. End Sub

    at the bottom?
    Wayne

Page 1 of 2 12 LastLast

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