VBScript syntax for testing multiple values for a single variable without using multiple "OR" operators

Posted on 2006-04-12
Last Modified: 2010-05-18
What is the syntax for the determining whether a variable matches a value in a set.  

For example, if I want to determine whether or not a variable is equal to one of many values
if (SECTIONABV = "ACC") or (SECTIONABV = "AIM") or (SECTIONABV = "YYY") or .... then
    do something
end if

I would prefer to compare against a set of values, something like this

if SECTIONABV in ("ACC","AIM","YYY") then
    do something
end if

Question by:despitia2
    1 Comment
    LVL 65

    Accepted Solution

    Select Case SECTIONABV
       Case "ACC", "AIM", "YYY"
          'Do that stuff
       Case Else
          'Do other stuff
    End Select

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now