Question
I am having trouble with the follow code. If a non-numeric value is entered I get my error message but after I click ok it
I am having trouble with the follow code. If a non-numeric value is entered I get my error message but after I click ok it still trys to do the calculation even though it was a non-neumeric value. Any suggestions would be appreciated.
Public Class frmCashForGold Private Sub radComputeTheWeight_CheckedChanged(sender As Object, e As EventArgs) Handles radComputeTheWeight.CheckedChanged ' User selects radio button to choose to calculat the goal amount lblEnterGold.Visible = False txtGoldAmount.Visible = False lblTargetGoal.Visible = True txtTargetGoal.Visible = True txtTotal.Text = "" txtGoldAmount.Text = ""
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub radComputeTheAmount_CheckedChanged(sender As Object, e As EventArgs) Handles radComputeTheAmount.CheckedChanged lblTargetGoal.Visible = False txtTargetGoal.Visible = False lblEnterGold.Visible = True txtGoldAmount.Visible = True txtTargetGoal.Text = "" txtTotal.Text = "" End Sub
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Dim TargetGoal As Double Dim EnterGold As Double Dim Total As Double Dim PricePerOunce As Integer = 1168.67
If IsNumeric(txtTargetGoal.Text) AndAlso IsNumeric(txtGoldAmount.Text) Then TargetGoal = Convert.ToDecimal(txtTargetGoal.Text) EnterGold = Convert.ToDecimal(txtGoldAmount.Text) ElseIf Not IsNumeric(txtTargetGoal.Text) And Not IsNumeric(txtGoldAmount.Text) Then MessageBox.Show("Please enter a numeric value")
End If
If radComputeTheWeight.Checked = True Then Total = CDbl(txtTargetGoal.Text) / PricePerOunce ElseIf radComputeTheAmount.Checked = True Then Total = CDbl(txtGoldAmount.Text) * PricePerOunce End If
Cash For Gold Cash For Gold Please Choose Your Option Please Select O Compute the weight in ounces to reach the goal amount O Compute the amount earned based on the weight of gold Target Goal Amount Enter the gold amount The calculated value is Calculate ClearStep 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