Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Instructions: Create a Windows application that contains two textboxes and two b

ID: 3681451 • Letter: I

Question

Instructions: Create a Windows application that contains two textboxes and two buttons. The textboxes should be used to allow the user to input two positive numeric values. The buttons should be labeled Add and Multiply. Create event-handler methods that retrieve the values, preform the calculations, and display the results of the calculations on a label. The result label should be initially be set to be invisible with a font color of yellow. If invalid data is entered, change the font color to red on the result label and display a message "Value must be numeric and >0." When the final answer is displayed, the font color should be yellow. Additional labels will be needed for the textboxes captions. Do not allow non-numeric characters to be entered. Invoke the TryParse() method to retrieve the values. All controls involved in program statements should be named. Right justify values in the textbox.

Explanation / Answer

Public Class Form1

Private Sub valid(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If Val(TextBox1.Text) < 0 Or Not IsNumeric(TextBox1.Text) Then
Label2.Show()
Label2.ForeColor = Color.Red
Label2.Text = "Pl. enter numeric data"
TextBox1.Clear()
TextBox1.Focus()
Else
Label2.Hide()

End If

End Sub

Private Sub TextBox2_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox2.Validating
If Val(TextBox2.Text) < 0 Or Not IsNumeric(TextBox2.Text) Then
Label2.Show()
Label2.ForeColor = Color.Red
Label2.Text = "Pl. enter numeric data"
TextBox2.Clear()
TextBox2.Focus()
Else
Label2.Hide()

End If
End Sub

  

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label2.Hide()
Label2.ForeColor = Color.Yellow

End Sub

Private Sub addbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addbtn.Click
Dim a, b As Integer
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
Label2.Show()
Label2.ForeColor = Color.Yellow
Label2.Text = a + b

End Sub

Private Sub multibtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles multibtn.Click
Dim a, b As Integer
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
Label2.Show()
Label2.ForeColor = Color.Yellow
Label2.Text = a * b

End Sub
End Class