This code defines two button click event handlers for an application. The btnExit_Click handler closes the application when the exit button is clicked. The btnCompare_Click handler compares two integer values entered in text boxes, checks that the values are valid integers, and displays which value is greater or if they are equal in a label.
This code defines two button click event handlers for an application. The btnExit_Click handler closes the application when the exit button is clicked. The btnCompare_Click handler compares two integer values entered in text boxes, checks that the values are valid integers, and displays which value is greater or if they are equal in a label.
Original Description:
Starting Out With Visual Basic 2012 - Programming Challenge 1
This code defines two button click event handlers for an application. The btnExit_Click handler closes the application when the exit button is clicked. The btnCompare_Click handler compares two integer values entered in text boxes, checks that the values are valid integers, and displays which value is greater or if they are equal in a label.
This code defines two button click event handlers for an application. The btnExit_Click handler closes the application when the exit button is clicked. The btnCompare_Click handler compares two integer values entered in text boxes, checks that the values are valid integers, and displays which value is greater or if they are equal in a label.
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
'Instructions for Exit button to closes application Me.Close() End Sub Private Sub btnCompare_Click(sender As Object, e As EventArgs) Handles btnCompare.Click 'Declare Local Variables Dim intValueA As Integer Dim intValueB As Integer With Me 'Determine if value A is an integer If Not Integer.TryParse(txtValueA.Text, intValueA) Then .lblResults.Text = "Value A is not a valid number, try again." With .txtValueA .Focus() .SelectAll() End With 'Determine if value B is an integer ElseIf Not Integer.TryParse(txtValueB.Text, intValueB) Then .lblResults.Text = "Value B is not a valid number, try again." With .txtValueB .Focus() .SelectAll() End With Else 'Determine which value is greater Select Case True Case intValueA = intValueB .lblResults.Text = "The values are equal." Case intValueA > intValueB .lblResults.Text = "Value A is greater than value B" Case intValueA < intValueB .lblResults.Text = "Value B is greater than value A" End Select End If End With End Sub End Class