Question If Statement with a numericupdown control

kieran82

Member
Joined
Feb 21, 2010
Messages
19
Programming Experience
Beginner
I have done some code so that when you choose a number from the numeriupdown it will look at the if statement and put the age into a category. the thing is the number in the updown doesnt go into the right category for me can you see what the problem is?

VB.NET:
    'Assigning Textboxes and Combo Boxes To Memory
        lblUsername.Text = Username
        strCustomerName = txtCustomerName.Text
        intCustomerAge = Val(NumericUpDownAge.Value)
        strStreet = txtCustomerStreet.Text
        strTown_City = txtCustomerTownCity.Text
        strCounty = txtCounty.Text
        strCountry = cboCustomerCountry.Text
        strArea_Code = Val(txtAreaCode.Text)
        strTelephoneNo = Val(txtCustomerPhoneNo.Text)
        strPostalCode = txtPostalCode.Text
        intNoOfDaysStay = Val(LblDays.Text)
        strPassportNo = MaskedTextBoxPassport.Text


        If intCustomerAge >= 18 <= 25 Then
            Ages_18To25 += 1
            intNoOfCustomers += 1
        ElseIf intCustomerAge >= 26 <= 35 Then
            Ages_26To35 += 1
            intNoOfCustomers += 1
        ElseIf intCustomerAge >= 36 <= 55 Then
            Ages_36To55 += 1
            intNoOfCustomers += 1
        ElseIf intCustomerAge >= 56 <= 80 Then
            Ages_56To80 += 1
            intNoOfCustomers += 1
        ElseIf intCustomerAge >= 81 <= 100 Then
            Ages_81To100 += 1
            intNoOfCustomers += 1
        End If
 
Well for one, this looks terribly wrong:
If intCustomerAge >= 18 <= 25 Then

Just like the rest of them. I believe you would want something like this:
VB.NET:
Select Case True
    Case intCustomerAge >= 18 AndAlso intCustomerAge <= 25
        Ages_18To25 += 1
        intNoOfCustomers += 1
    Case intCustomerAge  >= 26 AndAlso intCustomerAge <= 35
        Ages_26To35 += 1
        intNoOfCustomers += 1

    ...

    Case intCustomerAge  >= 81
        Ages_81To100 += 1
        intNoOfCustomers += 1
End Select
 
Back
Top