Rocky
Rocky

Reputation: 123

Click Button Event in VB that displays a message about user input

I have a really quick and simple question, I’m learning programming in C# and VB and I need to create a GUI application in Windows Form with Visual Studio. This GUI will prompt the user to enter in an integer. I believe I have this part alright but then I need to have the user click a button that will convert the user's entry to an integer and display a message indicating whether the user was successful. I think I even have the conversion done correctly but I am having a problem displaying that message if the user was successful. Basically I need to know how to function the click method in VB that will allow this message to appear. Any help with this would be greatly appreciated. The following code is what I have already written for this project:

Public Class Form1

    Private Sub EvaluateInput()
        Dim InputValue As String
        InputValue = ValueTextBox.Text
        If IsNumeric(InputValue) Then
            MessageBox.Show(InputValue & " is a number.")
        Else
            MessageBox.Show(InputValue & " is not a number.")
        End If
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click 'Continue Button

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Exit Button
        Dim button As DialogResult
        button = MessageBox.Show _
        ("Are you sure you want to exit this application?", _
        "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)

        If button = Windows.Forms.DialogResult.Yes Then
            Me.Close()
        Else
            'Do Nothing    
        End If
    End Sub
End Class

Upvotes: 0

Views: 14734

Answers (1)

Holger Brandt
Holger Brandt

Reputation: 4354

If I understand your question correctly, then you would need a simply change:

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) _
        Handles Button2.Click 'Continue Button
  EvaluateInput()
End Sub

When you press Button2, it will call the EvaluateInput sub and display a message accordingly.

Upvotes: 1

Related Questions