Click here to Skip to main content
15,921,990 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to add a message box [yes/no message box] that asks the user if he wants to clear the text boxes or not, if the user clicks yeas the text boxes are cleared and if no then the text boxes remain the same. This is the code used

What I have tried:

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        MsgBox("Do you want to clear all?", MsgBoxStyle.YesNo, "Clear the textboxes!")
        If MsgBoxResult.No Then
            TB1.Text = "0"
            TB2.Text = "0"
            TB3.Text = "0"
            TB4.Text = "0"
            TB5.Text = "0"
            L1.Text = "0"
            L2.Text = "0"
            L3.Text = "0"
            L4.Text = "0"
            L5.Text = "0"
            SCORE.Text = "0"
            Label10.Text = "Here"
        Else
            'what to put over here??
        End If
    End Sub
Posted
Updated 21-Oct-17 6:30am

1 solution

Reverse your test:
VB
MsgBox("Do you want to clear all?", MsgBoxStyle.YesNo, "Clear the textboxes!")
If MsgBoxResult.Yes Then
    TB1.Text = "0"
    TB2.Text = "0"
    TB3.Text = "0"
    TB4.Text = "0"
    TB5.Text = "0"
    L1.Text = "0"
    L2.Text = "0"
    L3.Text = "0"
    L4.Text = "0"
    L5.Text = "0"
    SCORE.Text = "0"
    Label10.Text = "Here"
End If
But please, start using .NET classes instead of outdated VB6 ones: MessageBox Class (System.Windows.Forms)[^]
 
Share this answer
 
Comments
Dave Kreskowiak 21-Oct-17 14:01pm    
Ummm... don't you want to put the return value from the messagebox into a variable and then compare that to the Yes result?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900