Instruction: Bonus
Develop a calculator application that will allow the user to enter the desired calculation (A for Addition, S for Subtraction) and enter two numbers.
When “Calculate” button is clicked, if the user entered two numbers, the application will display the appropriate result. Otherwise, a message box will show “You did not enter two numbers”, then quit the application. (Hint: use function IsNumeric)Question
Is there any better way I could haven't written this? Did I write the code correct? What other way I can write this?
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim Num1 As String
Dim Num2 As String
Dim AorS As String
Dim result As String
Num1 = ((txtFirst.Text))
Num2 = (txtSecond.Text)
AorS = txtEnter.Text.ToUpper
result = txtResult.Text
If IsNumeric(Num1) = True And
IsNumeric(Num2) = True And
AorS = "A" Then
result = CStr(CDbl(Num1) + CDbl(Num2))
End If
If IsNumeric(Num1) = True And
IsNumeric(Num2) = True And
AorS = "S" Then
result = CStr((CDbl(Num1) - CDbl(Num2)))
End If
If IsNumeric(Num1) = False Or
IsNumeric(Num2) = False Or
AorS = "" Then
MessageBox.Show(" You Did Not Enter A Valid Entry! ")
End If