Page 1 of 1

MsgBox Help

Posted: Wed May 16, 2012 5:42 am
by Mr.Wilson
I am trying to use MsgBox to display a message with yes no boxes and then use the results from the user to decide the next action. I am having troubles left and right. 1st Option Strict is having fits about conversions and if i turn off option strict the program executes but the"No" Button doesn't do any thing at all. I have tried to dim answer as an Integer aswell but it doesnt work either. How do i correct this issue. My goal is to have the user recieve the MsgBox ata certain point and then based on their decision (Yes or No)have the program repeat or not.
Any help would be appreciated.

Here is a sample of the code.
Code: Select all
Dim answer As MsgBoxResult
MsgBox("Congrats yadda yadda.",MsgBoxStyle.YesNo,"MsgBoxTitle.")
    If MsgBoxResult.Yes Then
      Yadda Yadda Whole Lot Of Code yadda yadda
    Else
      Default Msg
    EndIf
Continue with Program
Continue with Program
Continue with Program
Continue with Program

Re: MsgBox Help

Posted: Wed May 16, 2012 6:13 am
by Filip
Hello,

this should work;
Code: Select all
  Dim dr As New DialogResult
        dr = MsgBox("Question", MsgBoxStyle.YesNo, "Title")
        If dr = Windows.Forms.DialogResult.Yes Then
            'Do something
        Else
            Exit Sub
        End If

Re: MsgBox Help

Posted: Wed May 16, 2012 9:29 am
by comathi
visioncr0 wrote:
Hello,

this should work;
Code: Select all
  Dim dr As New DialogResult
        dr = MsgBox("Question", MsgBoxStyle.YesNo, "Title")
        If dr = Windows.Forms.DialogResult.Yes Then
            'Do something
        Else
            Exit Sub
        End If
Actually, I don't think that would work, as MsgBox is a legacy control from VB6. Instead, you should use Messagebox.Show, like so:
Code: Select all
Dim result As Windows.Forms.DialogResult= MessageBox.Show("Message", "Title",Buttons, icon)
Select Case Result
    Case Is= Windows.Forms.DialogResult.Yes
'Do something
Case Is=Windows.Forms.DialogResult.No
'Do something else
End Select

Re: MsgBox Help

Posted: Wed May 16, 2012 12:47 pm
by MrAksel
None of the above works :lol:
Code: Select all
Dim result As Windows.Forms.DialogResult = MessageBox.Show("Message", "Title", MessageBoxButtons.YesNo)
If result = DialogResult.Yes Then
 'Yes'
Else
 'No'
End If

Re: MsgBox Help

Posted: Wed May 16, 2012 1:43 pm
by Filip
MrAksel wrote:
None of the above works :lol:
Code: Select all
Dim result As Windows.Forms.DialogResult = MessageBox.Show("Message", "Title", MessageBoxButtons.YesNo)
If result = DialogResult.Yes Then
 'Yes'
Else
 'No'
End If
It's almost the same, and my code works (I tested it)

Re: MsgBox Help

Posted: Wed May 16, 2012 7:23 pm
by MrAksel
I thought the "New" in "Dim dr As New DialogResult" would generate a compiler error, but sorry :)