I am using Visual Basic Express, I hope you all still can help me. This program is used to calculate a cars speed related to speed limit. It has two user inputs, cars speed and speed limit. It will calculate any two digit # and one digit #, but when I input a three digit # the output comes out as 0. Please Help!!! (Just trying to learn, Thank You)

PublicClass Form1

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim i As Double = 0 '// Declaring Variabe as Integer Data Type

If TextBox1.Text > TextBox2.Text Then '// If Box 1 is greater than box 2

Do While i < Double.Parse(TextBox1.Text - TextBox2.Text) '// while i(which is equal to zero) is less than our integer, Box 1 - Box 2

i += 1 '// i = i + 1, 0 = 0 + 1 ?????

Loop
MessageBox.Show("The Calculated speed is " & i.ToString() & " miles under the speed limit.") '// Message in our MessageBox

TextBox1.Text = ""
TextBox2.Text = ""
Else

If TextBox1.Text < TextBox2.Text Then

Do While i < Double.Parse(TextBox2.Text - TextBox1.Text) '// while i(which is equal to zero) is less than our integer, Box 2 - Box 1

i += 1 '// i = i + 1, 0 = 0 + 1 ?????

Loop
MessageBox.Show("The Calculated speed is " & i.ToString() & " miles over the speed limit.") '// Message in our MessageBox

TextBox1.Text = ""
TextBox2.Text = ""
End If
End If

End Sub
EndClass

2
Contributors
2
Replies
4
Views
11 Years
Discussion Span
Last Post by WhYuLoOkIn

Hi,

Where u r inputting 3rd Digit..?
I think this would suffice, U dont have to put in a Loop, to Calculate the Difference between 2 Values.

``````Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Double
If Val(TextBox1.Text) > Val(TextBox2.Text) Then
i = Val(TextBox1.Text) - Val(TextBox2.Text)
Else
i = Val(TextBox2.Text) - Val(TextBox1.Text)
End If
MsgBox("The Calculated speed is " & i.ToString() )
End Sub``````

Regards
Veena

Thanks alot, I really appreciate the help that you all offer. I have been trying to figure that one out for a week.