Results 1 to 6 of 6

Thread: [RESOLVED] VB 6.0 Upon Exiting a Program (Are you sure Message Box)

  1. #1

    Thread Starter
    Junior Member GreeDee's Avatar
    Join Date
    Sep 2005
    Posts
    20

    Resolved [RESOLVED] VB 6.0 Upon Exiting a Program (Are you sure Message Box)

    Hi to the VB masters.

    I'm using VB 6.0 and I know this is an easy question, but my textbook doesn't cover it. I was sick the day our professor went over it. He wants us to create an |Are you sure you wish to quit?| message box connected to the Exit command button with Yes and No command buttons on it.

    He also wants us to include an image of the ! on the message box, not in text but as an image, and I can't find it anywhere in our textbook. Is this something I have to set up a separate form for, or is it simply code?

    No hurry it isn't due until Wednesday evening but any help you could provide would be invaluable to me.

    Thanks in advance.

  2. #2
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: VB 6.0 Upon Exiting a Program (Are you sure Message Box)

    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2.     If MsgBox("Are you sure you want to exit ?", vbExclamation + vbYesNo) = vbNo Then
    3.         Cancel = 1
    4.     End If
    5. End Sub

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: VB 6.0 Upon Exiting a Program (Are you sure Message Box)

    Assuming your exit button is called cmdExit...
    VB Code:
    1. Private Sub cmdExit_Click()
    2.     If MsgBox("Are you sure you want to exit?", vbExclamation + vbYesNo) = vbNo Then
    3.         Exit Sub
    4.     End If
    5.     Unload me
    6. End Sub

  4. #4
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: VB 6.0 Upon Exiting a Program (Are you sure Message Box)

    you can put it in the form unload sub too
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  5. #5
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: VB 6.0 Upon Exiting a Program (Are you sure Message Box)

    I think you need a combination of Deepak and Martin's solutions.

    Deepak's suggestion will show the message box when the form tries to close, however this occurs (either from the X button on the title bar, or from one of your own buttons)

    Martin's suggestion shows how to unload a form from one of your own buttons.

    I'd suggest keeping the Unload Me in Martin's button and letting Deepak's code take care of the message box.
    This world is not my home. I'm just passing through.

  6. #6

    Thread Starter
    Junior Member GreeDee's Avatar
    Join Date
    Sep 2005
    Posts
    20

    Re: VB 6.0 Upon Exiting a Program (Are you sure Message Box)

    Thank you all very very much. I will be sure and mark this topic "Resolved!" Many thanks for stopping into the new guy topic.

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