Results 1 to 13 of 13

Thread: END statement

  1. #1
    Pirre001
    Guest

    Question END statement

    I use END statement when the user press the Cancel button on my vbYesNoCancel MsgBox.
    But when I use the End statement it clear all my variables.
    But I wanna preserve the value of my variables. And I use the Stop statement instead. But it doesen't work? Why?

  2. #2
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs up Try this...

    Don't put any code in CANCEL event...

    I hope that you don't want to close you app with END...

    Dim intYesNo as Integer

    intYesNo = msgbox ("TEST",vbYesNoCancel)

    if intYesNo = vbYes then

    ' Do something

    endif

    if intYesNo = vbNo then

    ' Do something

    endif

    ==============

  3. #3
    Pirre001
    Guest
    If I don't put any code in CANCEL event my code continue to next sub...

  4. #4
    Addicted Member
    Join Date
    Aug 2000
    Location
    Adelaide - Australia
    Posts
    150
    if intYesNo = vbCancel then

    Exit sub

    end if

  5. #5
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Question what exactly you want to do...

    Do want to CLOSE the app or just get out of that sub...???

    if you just want to get out of sub then use GARY's code...

    or post here what exactly you are looking for...

    Cheers..........

  6. #6
    Pirre001
    Guest
    I don't want to CLOSE the app...only STOP the current subs and functions and when I use the End statement it clear all my variables.
    But I wanna preserve the value of my variables...

  7. #7
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs up OK then...

    Dim I As Integer

    I = MsgBox("TEST", vbYesNoCancel)
    If I = vbYes Then
    MsgBox "YES"
    End If

    If I = vbNo Then
    MsgBox "NO"
    End If

    If I = vbCancel Then
    End
    End If

  8. #8
    Stiletto
    Guest
    Originally posted by Gary007
    if intYesNo = vbCancel then

    Exit sub

    end if
    Use this. If you want to close your app when the user clicks Cancel use this:
    VB Code:
    1. if intYesNo = vbCancel then
    2. Unload me
    3. end if

  9. #9
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Do you mean you want to close you application, but want to preserve the value of your variables?

    If you close an application, the memory will be cleared, so if you want to save them, you will have to write them to disk somehow, and read them in when you start the application again.

    There are numerous ways to save something to disk, like a database, the registry, a text file, an XML file etc.

  10. #10
    Pirre001
    Guest
    I don't want to CLOSE the app...only STOP the current subs and functions and when I use the End statement it clear all my variables.
    But I wanna preserve the value of my variables...

  11. #11
    Swatty
    Guest
    You can only stop the current sub.

    If you want to jump out of the calling sub then you have to use parameters.

    If the value given is from jump out of sub (Exit Sub)
    then exit the calling sub too.

    Hope this clears your mind.

    If not post some code to show the place you are trying to exit

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

    Well

    Two things :

    First : Don't use END.

    Use :

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

    Second : How do you want to store the variables? As mentioned, there are many different options...
    Remaining quiet down here !!!

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

  13. #13
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    VB Code:
    1. If MsgBox("This is the message" vbYesNoCancel, "Title") = vbCancel Then
    2.   Exit Sub
    3. End If

    If the variables you want to preserve are declared in this sub they won't be preserved, you will have to declare them in the General Declarations.
    "I have not failed. I've just found 10,000 ways that won't work."
    'Thomas Edison'

    "If we knew what it was we were doing it wouldn't be called research, would it?"
    'Albert Einstein'

    VB6

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