Announcement

Collapse
No announcement yet.

Check if a value is in a list of predefined values

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Check if a value is in a list of predefined values

    I'm checking to see if an error variable is one of many specific values as such:

    On Error Resume Next
    colMembers = objGroup.GetEx("memberOf")
    If Err.Number In ("-2147463168", "424") Then
    ....
    Is there a way to do this in VB Script?
    |
    +-- JDMils
    |
    +-- Regional Systems Engineer, DotNet programmer & Jack of all trades
    |

  • #2
    Re: Check if a value is in a list of predefined values

    Instead of using 'If-Then':
    If (err = -2147463168) OR (err = 424) Then
    <....>
    End If


    You can use 'Select Case':
    Select Case Err.Number
    Case -2147463168, 424
    <...>
    End Select



    sample
    Code:
    On Error Resume Next
    Err.Raise 424   'testing\
    
    If (err) then  'optional 
    
     Select case Err.number
    
      Case -2147463168, 424
        Err.HelpFile = "userhelp.hlp"
        Err.HelpContext = usercontextID
        MsgBox Err.Description & vbNewLine & "Press F1 for help" _
           ,,"Error: [" & Err.number & "]" _
           ,Err.Helpfile, Err.HelpContext
        Err.Clear  'good practize is always clear/change the error after dealing with it
        
      Case Else
        MsgBox Err.Description  _
           ,,"Error: [" & Err.number & "]"
        Err.Clear
    
     End Select
    
     wscript.Quit(0)
    End If
    
    On Error GoTo 0
    Wscript.echo "No Errors raised"
    \Rems
    Last edited by Rems; 13th November 2007, 09:08. Reason: added colors

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Check if a value is in a list of predefined values

      Cool, thanks REMS. I'm so used to using .Net with its IN statement that it's hard to remember the syntax of VBS. I like the Select Case construct!
      Last edited by JDMils; 13th November 2007, 23:38.
      |
      +-- JDMils
      |
      +-- Regional Systems Engineer, DotNet programmer & Jack of all trades
      |

      Comment

      Working...
      X