[Help]Message Box[Solved]

Posts 1–15 of 17 · Page 1 of 2
[Help]Message Box[Solved]
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
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.
Quote Originally Posted by o0OpurezO0o View Post
it still goes to the "Yes" Command.

Does anyone know?


Thanks Haddson.
No Problem. Btw, my name's Hassan xD !
Quote Originally Posted by o0OpurezO0o View Post
it still goes to the "Yes" Command.

Does anyone know?


Thanks Haddson.
maybe because its already saved
Quote Originally Posted by willrulz188 View Post
maybe because its already saved

Haddson....ahahahaha
Quote Originally Posted by Blubb1337 View Post
Haddson....ahahahaha
Lol'd too. Get on MSN -.-
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



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.



Let me quote my self:

Yes, the best way is to declare the result if you the possibility of more than two return values.
You should've read that before giving me a lecture. Thank you.
*Correction in bold*.
Quote Originally Posted by Born2Amuse View Post
Let me quote my self:

Yes, the best way is to declare the result if you the possibility of more than two return values.
You should've read that before giving me a lecture. Thank you.
*Correction in bold*.
Well, you are right but you can't argue with him. Get used to it already.
Posts 1–15 of 17 · Page 1 of 2
This thread is closed for replies.

Tags for this Thread

None

Talk with us