Question
VB.Net, Calculator project that has 2 Text Boxes for number entry, a drop down list, OperatorList, for math operator, and a Calculate button. I need
VB.Net, Calculator project that has 2 Text Boxes for number entry, a drop down list, "OperatorList", for math operator, and a Calculate button.
I need to display a message on the "Result Label", not a message box, stating "You cannot divide by zero". My code is below but the message won't display. Please help.
Protected Sub CalculateButton_Click(sender As Object, e As EventArgs) Handles CalculateButton.Click If ValueBox1.Text.Length > 0 AndAlso ValueBox2.Text.Length > 0 Then
Dim result As Double = 0 Dim value1 As Double = Convert.ToDouble(ValueBox1.Text) Dim value2 As Double = Convert.ToDouble(ValueBox2.Text)
Select Case OperatorList.SelectedValue Case "+" result = value1 + value2 Case "-" result = value1 - value2 Case "*" result = value1 * value2 Case "/" result = value1 / value2 End Select If OperatorList.SelectedValue = "/" Then If value2 <> 0 Then ResultLable.Text = "You cannot divide by Zero" Else result = value1 / value2 End If End If ResultLable.Text = result.ToString() Else ResultLable.Text = String.Empty End If End Sub
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started