If MsgBoxResult.Yes then
*Private Coding*
End If
'Nothing else so you dont need it
If MsgBoxResult.Cancel Then
Exit sub
'or e.cancel
End If
I was trying to make a notepad with a Advance save system, the code is:
MsgBox("Do you want to Save?", vbQuestion+vbYesNoCancel, "Do you want to Save?")
If MsgBoxResult.Yes then
*Private Coding*
End If
If MsgBoxResult.No Then
End
End If
If MsgBoxResult.Cancel Then
Stop
End If
It keeps skipping and going to the save if i hit "No" or "Cancel".
Whats wrong? Anything Missing?
If MsgBoxResult.Yes then
*Private Coding*
End If
'Nothing else so you dont need it
If MsgBoxResult.Cancel Then
Exit sub
'or e.cancel
End If
Last edited by willrulz188; 01-23-2011 at 11:55 AM.
Question ALL statements! ?[img]https://i360.photobucke*****m/albums/oo45/blood188/Untitled-3.jpg?t=1284590977[/img]You're in denial that you're in denial. ?
Code:Dim i As Integer = MsgBox("Do you want to Save?", vbQuestion+vbYesNoCancel, "Do you want to Save?") If i = 2 Then Stop Elseif i=6 Then *Private Coding* Elseif i = 7 Then End End If
it still goes to the "Yes" Command.
Does anyone know?
Thanks Haddson.
Last edited by o0OpurezO0o; 01-23-2011 at 12:47 PM.
Haddson....ahahahaha![]()
Code:Dim Msgbox1 As DialogResult = MsgBox("AHAHAHA", MsgBoxStyle.YesNoCancel Or MsgBoxStyle.Question, "AHAHA") If Msgbox1 = Windows.Forms.DialogResult.Yes Then MsgBox("You Pressed YES") ElseIf Msgbox1 = Windows.Forms.DialogResult.No Then MsgBox("You Pressed NO") ElseIf Msgbox1 = Windows.Forms.DialogResult.Cancel Then MsgBox("You Pressed CAncel") End If
Code structure is wrong. In your code you have
[highlight=vbnet]
MsgBox("Do you want to Save?", vbQuestion+vbYesNoCancel, "Do you want to Save?")
If MsgBoxResult.Yes then
*Private Coding*
End If
If MsgBoxResult.No Then
End
End If
If MsgBoxResult.Cancel Then
Stop
End If
[/highlight]
It should be
[highlight=vbnet]
Dim Result As DialogResult
Result = MessageBox.Show("Do you want to save?", "Save?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
'This will check what was clicked inside the dialog box declared as result
If Result = vbYes Then
'Your Code
ElseIf Result = vbNo Then
'Something else
ElseIf Result = vbCancel Then
'do nothiing
End If
[/highlight]
There should be no issues, let me know.
Fact is , it's all about the code and how it is structured, If statements should not end until you are done checking for what you want to check for.
In the same way a real If-->then Statement works.
If I have an apple
I have an Orange
Elseif I have a pinapple
I do not have a apple
----------------------
I do not have an Pineapple.
What is then true?
You can check to see if I have an apple, and can assume I do, but you will also have to continue to check and see If I have an orange (which I do) if you end the check there, you will never find that I have an orange
abstract explanation, but hopefully you understand.
Plus it is best to declare the result anyway![]()
Last edited by NextGen1; 01-23-2011 at 02:51 PM.
Yes, the best way is to declare the result if you the possibility of more than two return types, otherwise you can use the following format:
[highlight=vbnet]If Msgbox("Do you want to retry ?", MsgBoxStyle.YesNo,"Msgbox Test")=MsgboxResult.vbYes Then
Msgbox("You pressed Yes")
Else
Msgbox("You pressed No")
End If[/highlight]
Can save some lines, but doesn't really matter.
Kinda does matter, But irrelevant,
in either case however, By declaring it first you leave yourself open for numerous options and many ways to use it, your way is static, used for yesno only, in this case we can use
Okonly,Yesno,YesNoCancel,Okcanel, You get the idea. Yours wouldn't even work with his scenario.
Last edited by NextGen1; 01-23-2011 at 10:06 PM.
Let me quote my self:
You should've read that before giving me a lecture. Thank you.Yes, the best way is to declare the result if you the possibility of more than two return values.
*Correction in bold*.