compare Textbox input to Int variables and display result

I'm fairly new to I’m trying to create a hypothetical project. please see attachments!

I have a win-form (see car2 attachment) with x3 textboxes:
Textbox1 = Car-Len
Textbox2 = Car-Height
Textbox3 = Car-Width
and lots of labels.

The idea is:
input car Length, Width, Height in to their textboxes and if (for example: London Garage has a value greater than – say Length, then Y appears in a Label next to London and same for other two boxes.  Hope that made sense.

So in a nut shell:  I put dimensions of a car into Textboxes and if compared to Garage London dimensions, then label(s) say yes or no... so, basically, does the car fit in garage - phew!!!
Below is my shocking attempt at code (WHICH DOESN'T WORK) (i suspect it's something to do with string to int conversion - I'm just guessing!
  Dim LondonH As Integer = 5 ' 8 feet
    Dim LondonW As Integer = 5 ' 9 to 10 feet wide
    Dim LondonL As Integer = 13 '18 to 20 feet long
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Label1.Text = "London"
        Label2.Text = "Paris"
        Label3.Text = "Italy"
    End Sub

    Private Sub TextBox3_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox3.TextChanged
        ' len
        If Val(TextBox1.Text) < LondonL Then
            Label7.Text = "n"
        ElseIf Val(TextBox1.Text) > LondonL Then
            Label7.Text = "y"
        End If
    End Sub

Open in new window

Many thanks,
Robert FreemanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
instead of Val, use:

Éric MoreauSenior .Net ConsultantCommented:
One thing I see is that this event is handling the TextBox3 TextChanged event and inside the event handler, you are using TextBox1. This does not look right to me!
Fernando SotoRetiredCommented:
Hi Robert;

Please try code like this.
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged

    '' Reset the control
    Label7.Text = ""
    '' TryParse will fill this variable with the converted value
    Dim len = -1

    '' Make sure there is something to test in the TextBox1
    If String.IsNullOrWhiteSpace(TextBox1.Text) Then Return

    '' Test the value in TextBox1 and take the correct action
    If Int32.TryParse(TextBox1.Text, len) Then
        If len <= LondonL Then
            Label7.Text = "y"
            Label7.Text = "n"
        End If
        '' Invalid text value found in the TextBox1
        MessageBox.Show("Invalid character was entered. Please correct.")
    End If

End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David Johnson, CD, MVPOwnerCommented:
Public Class Form1
    Dim LondonH As Integer = 8
    Dim LondonW As Integer = 10
    Dim LondonL As Integer = 20
    Dim London As String

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        London = "N"

            If ((CInt(TextBox1.Text) < LondonH) And (CInt(TextBox2.Text) < LondonW) And (CInt(TextBox3.Text) < LondonL)) Then
                London = "Y"
            End If
            Label7.Text = London
            MessageBox.Show("Length Width Height must be Entered as Whole Numbers")
        End Try
    End Sub
End Class

Open in new window

Fernando SotoRetiredCommented:
Most complete answers.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.