Link to home
Start Free TrialLog in
Avatar of Robert Freeman
Robert Freeman

asked on

compare Textbox input to Int variables and display result

I'm fairly new to VB.net. 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
car2.png
car.png
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

instead of Val, use:

convert.int32
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!
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Most complete answers.