Results 1 to 5 of 5

Thread: [RESOLVED] Case or If Statement

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    Resolved [RESOLVED] Case or If Statement

    I want to use a case or an if statement to launch IE to a certain website if the user is from a certain state.

    I was trying to put together a case statement that went something like this but it is in the wrong format and I'm not sure it is possible to do this with case:

    VB Code:
    1. Select Case strState
    2.  
    3. Case AK or AL or AR
    4.     'Do Stuff
    5.  
    6. Case WA or WY or WV
    7.     'Do Stuff

    Is this possible to make the case a list of values like this or should I be using if statements?
    CodeBank: Launch IE

  2. #2
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Case or If Statement

    use a comma instead of the "Or"

    Case AK, AL, AR

    quotes round them if they are not variables ofcourse

    casey.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    Re: Case or If Statement

    Thanks, that worked...

    Now I've got another problem with the case statement though. Here is my case statement. It is not setting strURL to the correct website for some reason when strState is either "AK" or "AL". When stepping through the code it skips over the 'strURL = "www.google.com"' part even when the state matches the state for that case.

    VB Code:
    1. Select Case strState
    2.     Case strState = "AK", "CO", "DC", "DE", "HI", "ID", "IL", "IN", "KY", "MA", "MD", "MI", "MN", "MT", "NC", "ND", "NJ", "NY", "NH", "OH", "PA", "SD", "TN", "UT", "VA", "WA", "WI", "WV", "WY"
    3.         strURL = "http://www.google.com"
    4.     Case strState = "AL", "AR", "AZ", "CA", "CT", "FL", "GA", "IA", "KS", "LA", "ME", "MO", "MS", "NE", "NH", "NM", "NV", "OK", "PR", "RI", "TX", "VT"
    5.         strURL = "http://www.yahoo.com"
    6. End Select

    Any ideas? All the other states work correctly just the first one in each case.
    CodeBank: Launch IE

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Case or If Statement

    Don't use

    Case strState = "AK", "CO"

    The first part is an expression, which evaluates to True or False. The Select Case statement would then be

    Select Case "AK"
    Case True, "CO"


    VB Code:
    1. Select Case strState
    2.     Case "AK", "CO", "DC", "DE", "HI", "ID", "IL", "IN", "KY", "MA", "MD", "MI", "MN", "MT", "NC", "ND", "NJ", "NY", "NH", "OH", "PA", "SD", "TN", "UT", "VA", "WA", "WI", "WV", "WY"
    3.         strURL = "http://www.google.com"
    4.     Case  "AL", "AR", "AZ", "CA", "CT", "FL", "GA", "IA", "KS", "LA", "ME", "MO", "MS", "NE", "NH", "NM", "NV", "OK", "PR", "RI", "TX", "VT"
    5.         strURL = "http://www.yahoo.com"
    6. End Select

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    Re: Case or If Statement

    Thanks, that cleared it up...
    CodeBank: Launch IE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width