Results 1 to 3 of 3

Thread: comparing against a range of values

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2003
    Posts
    16

    comparing against a range of values

    Does anyone know of a way to a compare a single value against a range of values, like you can do with the SQL IN() statement?
    In SQL you can say:

    SELECT * FROM tblAddress WHERE ZipCode IN('92131', '92156', '92163')

    and you will get any rows that have a ZipCode value matching any of the values in the brackets.

    In vb.net I want to say:

    If strZipCode In("92131", "92156", "92163") Then
    'do some stuff here
    End If

    but obviously there is no "In" statement in vb.net. I also want to get away from saying:

    If strZipCode = "92131" Or strZipCode = "92156" Or strZipCode = "92163" Then
    'do some stuff here
    End If

    This gets messy when there are many values.

    Any suggestions would be appreciated.

  2. #2
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi Denny.

    I think this will do the trick...

    VB Code:
    1. Dim S() As String = New String() {"92131", "92156", "92163"}
    2. If Array.IndexOf(S, strZipCode) <> -1 Then
    3.     MsgBox("Found")
    4. End If
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2003
    Posts
    16
    I think that will do it. Thanks for your help!

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