Results 1 to 16 of 16

Thread: MSGBOX help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    71

    MSGBOX help

    Hi, I was wondering how you could get a message box with a yes and no option to work. I know how to get the message box to come up, just don't understand how to make it so if they click no, then nothing happens and if they click yes then it will close.

    Private Sub mnuexit_Click()

    msgbox "Are you sure you want to quit?", vbyesno
    End
    End Sub


    With that code if you click no or yes it will close both times. Wondering how to make it so if you hit no nothing happens.

    Thanks

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: MSGBOX help

    VB Code:
    1. Private Sub mnuexit_Click()
    2.   If MsgBox("Are you sure you want to quit?", vbYesNo) = vbYes Then Unload Me
    3. End Sub

    you shouldn't use End to quit your application

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    71

    Re: MSGBOX help

    I usually use Unload FormMain or something like that, but I was just tring out different ways.

    Thanks

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    71

    Re: MSGBOX help

    Why not though? I don't see much of a difference.

  5. #5
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: MSGBOX help

    Quote Originally Posted by Grant1377
    Why not though? I don't see much of a difference.
    End doesn't let the application shut itself down. It's kind of like pulling the plug on your stereo. Unload [form] lets the application clean up after itself. It's more like stopping the CD player, then hitting the power button.

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: MSGBOX help

    Quote Originally Posted by MSDN
    The End statement stops code execution abruptly, without invoking the Unload, QueryUnload, or Terminate event, or any other Visual Basic code. Code you have placed in the Unload, QueryUnload, and Terminate events of forms and class modules is not executed. Objects created from class modules are destroyed, files opened using the Open statement are closed, and memory used by your program is freed. Object references held by other programs are invalidated.

    The End statement provides a way to force your program to halt. For normal termination of a Visual Basic program, you should unload all forms. Your program closes as soon as there are no other programs holding references to objects created from your public class modules and no code executing.
    i didn't think it freed up the memory, but apparently it does. But, yes, it is unadvised.

  7. #7
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: MSGBOX help

    If you're subclassing it will crash


    Has someone helped you? Then you can Rate their helpful post.

  8. #8
    Junior Member
    Join Date
    Oct 2005
    Posts
    22

    Re: MSGBOX help

    Back to the topic of the message boxes:

    when you do something like:
    VB Code:
    1. msgbox("Do you want to quit?", vbyesno)

    you need to use a variable, because using the "vbyesno" part means that the computer will record whether the user clicks "yes" or "no" so basically

    VB Code:
    1. dim Click as Integer
    2.  
    3. Click = msgbox("Do you want to quit?", vbyesno)
    4.  
    5. if click = vbyes then
    6.      unload me 'or end, for this part just look at the above post
    7. end if

    basically, the button the user clicks returns a 1 or a 0, I think, but i'm not sure, that 1 means yes. Either way, whichever one is returned is stored in the "click" variable, then the if statement checks what's in "Click",

    if the user clicked yes, it would unload the form, otherwise, it would simply close the msgbox and do nothing else.

  9. #9
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: MSGBOX help

    Here are the possible button arguments
    Code:
    Constant		Value	Description
    vbOKOnly		0	Display OK button only.
    vbOKCancel		1	Display OK and Cancel buttons.
    vbAbortRetryIgnore	2	Display Abort, Retry, and Ignore buttons.
    vbYesNoCancel		3	Display Yes, No, and Cancel buttons.
    vbYesNo			4	Display Yes and No buttons.
    vbRetryCancel		5	Display Retry and Cancel buttons.
    vbCritical		16	Display Critical Message icon. 
    vbQuestion		32	Display Warning Query icon.
    vbExclamation		48	Display Warning Message icon.
    vbInformation		64	Display Information Message icon.
    vbDefaultButton1	0	First button is default.
    vbDefaultButton2	256	Second button is default.
    vbDefaultButton3	512	Third button is default.
    vbDefaultButton4	768	Fourth button is default.
    vbApplicationModal	0	Application modal; the user must respond to the message box before continuing work in the current application.
    vbSystemModal		4096	System modal; all applications are suspended until the user responds to the message box.
    vbMsgBoxHelpButton	16384	Adds Help button to the message box
    VbMsgBoxSetForeground	65536	Specifies the message box window as the foreground window
    vbMsgBoxRight		524288	Text is right aligned
    vbMsgBoxRtlReading	1048576	Specifies text should appear as right-to-left reading on Hebrew and Arabic systems
    And the return values
    Code:
    Constant	Value	Description
    vbOK		1	OK
    vbCancel	2	Cancel
    vbAbort		3	Abort
    vbRetry		4	Retry
    vbIgnore	5	Ignore
    vbYes		6	Yes
    vbNo		7	No

  10. #10

  11. #11
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: MSGBOX help

    I do in this way this, maybe a bit more need write, but i have larger possibilities – I think so.

    VB Code:
    1. If Your_variable= 1 Then
    2.   Other_variable = MsgBox( _
    3.         Prompt:=" Are you sure you want to change settings during calculation? _
    4.         Title:=" Unexpected change of settings!!", _
    5.         Buttons:=vbYesNo + vbQuestion)
    6.           If Other_variable = vbYes Then
    7.              Call cmdWrite_Click
    8.              OptLook.Value = True
    9.           Else
    10.              Exit Sub
    11.           End If
    12. End If

    I use these constants here: If constant = 6 is for vbYes and if constant = 7 is for vbNo
    I assign variable constans and in this way I can realize close MsgBoxes without realization any operation

    I think that it about this walked
    I know, I know, my English is bad, sorry .....

  12. #12
    Member
    Join Date
    Nov 2004
    Location
    California
    Posts
    46

    Re: MSGBOX help

    VB Code:
    1. Dim Msg$
    2.  
    3.   Msg = MsgBox("What ever you want the messege box to say", vbYesNo, "Title")
    4.  
    5.   Select Case Msg
    6.     Case vbYes
    7.         'code here
    8.     Case vbNo
    9.         'code here
    10.  
    11.    End Select
    God told me to skin u alive

  13. #13
    Junior Member
    Join Date
    Oct 2005
    Posts
    22

    Re: MSGBOX help

    Quote Originally Posted by bushmobile
    @ Scriptor: hadn't i already said that in post #2?
    Yeah, I know, sorry bout that, only noticed it after I posted mine, still, I explained what happens in the code, didn't I?

  14. #14
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Re: MSGBOX help

    try this.

    VB Code:
    1. Dim Result As VbMsgBoxResult
    2.  
    3.     Result = MsgBox("Are you sure you want to exit?", vbYesNo)
    4.    
    5.     If (Result = vbYes) Then
    6.         Unload Me
    7.     Else
    8.         Exit Sub
    9.     End If

  15. #15
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: MSGBOX help

    this question was answered a fortnight ago in posts #2, #8, #11, #12 - think he's got his answer

  16. #16
    Addicted Member
    Join Date
    Feb 2006
    Posts
    139

    Re: MSGBOX help

    dim m as variable
    m=msgbox("do you want to continue?"),vbquestion+vbyesno,"continue")
    if m=vbyes then
    the thing you want to do
    end if
    if m=vbno then

    end if

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