Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a value is in a list of numbers

Tags:

vbscript

Say I have a group of numbers 23,56,128,567 and I have to apply a conditional logic in which if a variable myData exists in the above group of numbers then only I proceed, otherwise I don't.

Sorry, have to look into some legacy code and not exactly sure how to do it in VBScript.

like image 801
sp9 Avatar asked Jan 13 '15 21:01

sp9


1 Answers

You could put the values in a Dictionary:

Set list = CreateObject("Scripting.Dictionary")
list.Add  23, True
list.Add  56, True
list.Add 128, True
list.Add 567, True

and then check if your value exists in the dictionary:

If list.Exists(myData) Then
  'do stuff
End If

An ArrayList would be another option:

Set list = CreateObject("System.Collections.ArrayList")
list.Add 23
list.Add 56
list.Add 128
list.Add 567

If list.Contains(myData) Then
  'do stuff
End If
like image 163
Ansgar Wiechers Avatar answered Sep 25 '22 01:09

Ansgar Wiechers