Visual Basic Zip Solution Ch. 8 Lesson B Exercise 15

I am coding a Button that displays the shipping charge when you enter a zip code. To be valid, the ZIP code must contain exactly 5 digits, and the first three digits must be either "605" or "606". The shipping charge for "605" ZIP codes is $25. The shipping charge for "606" ZIP codes is $30. Display an appropriate message if the ZIP code is invalid. I am having trouble finding a way to have the right price show up for the two different zip codes. Can anyone help me out?


Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        ' variable for shipping charge
        Dim strZip As String

        'remove any leading and trailing spaces
        strZip = txtZip.Text.Trim

        ' shipping price for zip code starting with 605
        If strZip Like "60[5-6]##" Then
            lblShipping.Text = "$25"



        Else
            MessageBox.Show("The Zip is invalid.", _
                            "Zip Code", MessageBoxButtons.OK, _
                            MessageBoxIcon.Information)

        End If

     

    End Sub
anault24Asked:
Who is Participating?

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

x
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.

Éric MoreauSenior .Net ConsultantCommented:
You could try:

Dim strZip As String = txtZip.Text.Trim
if strzip.length = 5 then
   if strzip.startwith("605")
            lblShipping.Text = "$25" 
   elseif strzip.startwith("606")
            lblShipping.Text = "$30" 
    Else
            MessageBox.Show("The Zip is invalid.", _
                            "Zip Code", MessageBoxButtons.OK, _
                            MessageBoxIcon.Information)

        End If
    Else
            MessageBox.Show("The Zip is invalid.", _
                            "Zip Code", MessageBoxButtons.OK, _
                            MessageBoxIcon.Information)

        End If

Open in new window

0

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
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 Classic

From novice to tech pro — start learning today.