Verify a string is present in an array using VBScript

In order to verify a string is present in an array, we will utilize the dictionary object provided by VBScript.

First, we will create an object of dictionary and then we will add the strings present in the array using a for loop. Once all the strings are added to the dictionary, then we will use exists function to check if the given string is already present in the array.

Example code: Verify a string is present in an array using VBScript
'=========================================================================================
'Function Name  - IsPresentInArray
'Arguments	- array, value
'Returns	- True or False
'Purpose	- Checks if val is present as one of the values in array arr
'Description	- This is to ckeck if a value val is present in the array arr
'=========================================================================================

Function IsPresentInArray(arr, val)
      ul= UBound(arr)
      Set objAL= CreateObject("Scripting.dictionary")

      For i = 0 To ul
        objAL.Add TRIM(UCASE(arr(i))),"Organization"

      Next

      Wait 0,500
      If objAL.Exists (UCASE(TRIM(val))) Then
        reporter.ReportEvent micDone,"Check presence of " & val & " in the array" ,"Present- " & join(arr,",")
        IsPresentInArray= True
        Else
        reporter.ReportEvent micDone,"Check presence of " & val & " in the array" , "Not Present- " & join(arr,",")
        IsPresentInArray= False
      End If

      Set objAL=Nothing
	
End Function

You may also read

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.