CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2001
    Posts
    26

    How can I terminate a program

    Hi

    How can I termiante a program with a command (like "Exit" in Pascal or "Return" in C)

    Thanks
    Ehsan


  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How can I terminate a program

    To terminate your program brutally, you can use "End" statement. I do suggest you to not use this word, anyway, but to Unload all forms and dinamically added controls, and to set to nothing all references to objects and forms. Example:
    unload form1
    set form1 = nothing

    Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Mar 2001
    Posts
    7

    Re: How can I terminate a program

    The Unload is not allways enough. The END statement definitely ends the program.
    This is an example. You have Textbox, Command1 and Command2 buttons. Press Command2
    and Do Loop begins, beeps once a second. Press Command1 to stop the program but it does not stop, it disappears but it beeps. So it is still running.

    Private Sub Command1_Click()
    Unload Form1
    Set Form1 = Nothing
    End Sub

    Private Sub Command2_Click()
    Dim a As Single, b As Single

    a = Timer
    Text1.Text = "Press Command1"

    Do

    b = Timer
    DoEvents

    If b - a > 1 Then
    Beep
    a = Timer
    End If

    Loop

    End Sub



  4. #4
    Join Date
    Mar 2001
    Posts
    26

    Re: How can I terminate a program

    Hi

    Thanks but i have some problems with unloading forms:

    I have a form with an activex on it and when I call unload form I receive an application error:

    The instruction at "..." refrenced memory at "...".
    the memory could not be read

    could u pls tell me What is the reason?

    Thanks Ehsan


  5. #5
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How can I terminate a program

    That is true, but it is a "dirty" end: you should stop your timer and exit loop before unloading: the process running will prevent your form from a truly unload...

    Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How can I terminate a program

    Look if this sounds familiar:
    you have one form
    you load the form from sub main
    you have an activex on the form
    you make the activex starts his job or you invoke a method or set a property of activex (or of the form) from somewhere else (not from sub main).
    Then you (maybe even if job is finished) try to unload the form...
    If you have declared something as "Public" in your form or activex,you can call it from everiwhere, but in the sametime, you will have a new reference to the object. You gain a new istance of object also when you use the "new" keyword
    (ie: set myx = new controlX). You have to set all references to nothing, before you can unload your form.
    Hope this was the matter.

    Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  7. #7
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: How can I terminate a program

    It might help if we knew what is the activex control that you're using and how are you using it.

    -Cool Bizs

    Good Luck,
    -Cool Bizs

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

Featured