MsgBox Help

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
6 posts Page 1 of 1
Contributors
User avatar
Mr.Wilson
New Member
New Member
Posts: 24
Joined: Sat Apr 23, 2011 3:42 pm

MsgBox Help
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
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: MsgBox Help
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
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: MsgBox Help
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
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: MsgBox Help
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
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: MsgBox Help
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)
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: MsgBox Help
MrAksel
I thought the "New" in "Dim dr As New DialogResult" would generate a compiler error, but sorry :)
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
6 posts Page 1 of 1
Return to “Coding Help & Support”