Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

I am doing a speed of sound VB project. The user enters the distance and select 1 of 3 radio buttons to select the material

I am doing a speed of sound VB project. The user enters the distance and select 1 of 3 radio buttons to select the material (air, water, or steel). User clicks and program determines how many seconds it will take to reach their entered distance. I can't seem to get my error message box to show up when I enter a negative number, 0, or a number spelled out.

The Calculate button must:

Not use exception handling to cast the string in the DistanceTextBox.Text to type Double. Rather, you must use the Double.TryParse() method for the type conversion and error handling on bad input.

Test for non-negative input. Any numeric distance input that is less than zero should generate an error message and no other output.

Only one error message must be displayed to the user for both types of errors indicated above. The message should say something like, ERROR: The distance entered must be a non-negative real number. and be displayed to the user via a MessageBox.

Here is my code thus far.

Private Sub CalculateButton_Click(sender As Object, e As EventArgs) Handles CalculateButton.Click Dim Distance As Integer DistanceTextBox.Text = Integer

If Not Integer.TryParse(DistanceTextBox.Text, Distance) Then MessageBox.Show("ERROR: The distance entered must be a non-negative real number.") End If

If AirRadioButton.Checked = True Then TimeOutputLabel.Text = CStr(FormatNumber(CDec(DistanceTextBox.Text) / 1100)) ElseIf WaterRadioButton.Checked = True Then TimeOutputLabel.Text = CStr(FormatNumber(CDec(DistanceTextBox.Text) / 4900)) ElseIf SteelRadioButton.Checked = True Then TimeOutputLabel.Text = CStr(FormatNumber(CDec(DistanceTextBox.Text) / 19400))

End If End Sub

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions