Post[HELP] MsgBoxStyle.YesNo[Solved]

Posts 1–13 of 13 · Page 1 of 1
[HELP] MsgBoxStyle.YesNo[Solved]
How Do I make it so if u click NO on the msgBox it will close.. here is my code im using..



[php]If TextBox1.Text = "hello" Then
MsgBox("Welcome_- Your PassWord Is -" + TextBox1.Text, MsgBoxStyle.YesNo)
If MsgBoxStyle.YesNo = "No" Then
Me.Close()
End If
Contents.Show()
Me.Hide()[/php]

Anyone Help
[php]Dim MsgResult as string

If TextBox1.Text = "hello" Then
MsgResult = MsgBox("Welcome_- Your PassWord Is -" + TextBox1.Text, MsgBoxStyle.YesNo)

If MsgResult = vbNo Then
Me.Close()
ElseIf MsgResult = vbYes Then
'You answered yes
End If

Contents.Show()
Me.Hide()[/php]

I'm not 100% sure about vbNo in VB.net but it would work like that in VB6
@Mintslice, I wrote a whole tutorial on msgbox's and how to use them, goto tutorial section .
Quote Originally Posted by MintSlice View Post
How Do I make it so if u click NO on the msgBox it will close.. here is my code im using..



[php]If TextBox1.Text = "hello" Then
MsgBox("Welcome_- Your PassWord Is -" + TextBox1.Text, MsgBoxStyle.YesNo)
If MsgBoxStyle.YesNo = "No" Then
Me.Close()
End If
Contents.Show()
Me.Hide()[/php]

Anyone Help
Code:
If Textbox1.text="Hello" Then
If MsgBox("Welcome_- Your PassWord Is -" + TextBox1.Text, MsgBoxStyle.YesNo)=MsgBoxResult.No Then
Me.Close()
End If
Contents.Show()
Me.Hide()
End If
I would use:
[php]If textbox1.text = "hello" then
dim x as msgboxresultat = Msgbox("Welcome_- Your PassWord Is -" + textBox1.Text,MsgBoxStyle.YesNo)
If x = MsgBoxResult.No Then
Me.Close()

End If
Contents.Show()
Me.Hide()


end if[/php]
whats IMO and thanks for all your ideas

edit : MJlover still dont work
Quote Originally Posted by MintSlice View Post
whats IMO and thanks for all your ideas

edit : MJlover still dont work
IMO = In My Opinion
IMHO = In My Humble Opinion

Solution

Note: I also made a few changes to your wording and how it was set up, I removed the underscores (_) and replaced them with proper spacing, You can use the & symbol to link words, phrases, and strings.

Example: Using Quick Basic to demonstrate how it works ...

Code:
Print "Hello"
Insert "What is your name"; Name$
Print "Hello" & " " & Name$
If you use the & Symbol, your result would be

Hello "Chosen Name"


[php]
Dim CloseMe As String
CloseMe = MsgBox("Welcome" & " " & "Your PassWord Is" & " " + TextBox1.Text, MsgBoxStyle.YesNo, Microsoft.VisualBasic.MsgBoxStyle.Exclamation + Microsoft.VisualBasic.MsgBoxStyle.YesNo + Microsoft.VisualBasic.MsgBoxStyle.MsgBoxHelp)
If TextBox1.Text = "hello" Then
If CloseMe = vbYes Then
' Contents.Show()
Else
Me.Close()
Me.Dispose()
End If
End If
End Sub
[/php]

The real problem with everyone elses examples is one of two things

the Code Rule (which I will Explain)

Or VbYesNo cannot be converted to type double

Code Rule, Code Reads from top to bottom, always, unless your code has specific calls to make them bounce, but if you are in a sub, expect the actions to be taken unless you specify otherwise.

Example :

[php]
If TextBox1.Text = "hello" Then
MsgBox("Welcome_- Your PassWord Is -" + TextBox1.Text, MsgBoxStyle.YesNo)
If MsgBoxStyle.YesNo = "No" Then
Me.Close()
End If
Contents.Show()
Me.Hide()
[/php]

after the End If your code says Contents.show and Me.Hide, what is to stop that code from running no matter what? , Closing the application?

...Nope..., The code will complete the sub.

Same for Hejsans example, so whenever you want a action to discontinue
use GOTO or Exit Sub

Next Issue in your example is that "Yes" is a string. That's a no go.

And finally @ MJ

MJ says

[php]
If Textbox1.text="Hello" Then
If MsgBox("Welcome_- Your PassWord Is -" + TextBox1.Text, MsgBoxStyle.YesNo)=MsgBoxResult.No Then
Me.Close()
End If
Contents.Show()
Me.Hide()
End If
[/php]

He was half way there, the problem with that is he is not creating a new instance of the message box,

So for Mj's example to work , it should be

[php]
Dim MJClose as String
MjClose = MsgBox("Welcome_- Your PassWord Is -" + TextBox1.Text, MsgBoxStyle.YesNo)
If Textbox1.text="Hello" Then
If mjclose = vbno then
Me.Close()
End If
End If
Contents.Show()
Me.Hide()
[/php]

but to make it work even better use the Else Statement.


[php]
Dim MJClose as String
MjClose = MsgBox("Welcome_- Your PassWord Is -" + TextBox1.Text, MsgBoxStyle.YesNo)
If Textbox1.text="Hello" Then
If mjclose = vbno then
Me.Close()
else
Contents.Show()
Me.Hide()
End If
End If
[/php]

In my example, we create a new instance of the message box

[php]
Dim CloseMe as String' , Here I make my declaration and say set it's data type to string.
[/php]

' Now we need to create a new instance.

[php]
CloseMe = "Welcome" & " " & "Your PassWord Is" & " " + TextBox1.Text, MsgBoxStyle.YesNo, Microsoft.VisualBasic.MsgBoxStyle.Exclamation + Microsoft.VisualBasic.MsgBoxStyle.YesNo + Microsoft.VisualBasic.MsgBoxStyle.MsgBoxHelp)
[/php]

What this does is allows me to create a new instance of that message box whenever I need it using

[php]
If Closeme = VByes
[/php]

or

[php]
If Closeme = VbNo
[/php]

Which will automatically create the message box and wait for the response.

Final conclusion to all this, Read my article and as well, be sure to keep everything where it should be.


Hope you understand this, and I hope you learn from it.

Holy Cow.. That Was alot of writing.
Better to explain then just to give an answer
You didn't say anything about my code? D:
Ha Ha, Erins code was close to right as well,
Its All Good Now.. I Decided not to put the MsgBoxStyle.YesNo

i just kept it simple

NextGen1 Please Close

/Req Close
Posts 1–13 of 13 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us