How to use VBScript array function "Filter" with WinBatch?
;==========================================================================================================================================
;
; How to use the VBScript array function "Filter(...)" from within WinBatch script?
;
;==========================================================================================================================================
; The VBScript function "Filter" returns a zero-based array that contains a subset of a string array based on a filter criteria.
;
; arrVB = Filter(inputstrings,value[,include[,compare]])
;
; Parameter Description:
;    inputstrings ... Required. A one-dimensional array of strings to be searched.
;    value .......... Required. The string to search for.
;    include ........ Optional. A Boolean value that indicates whether to return the substrings that include or exclude value.
;                     True returns the subset of the array that contains value as a substring.
;                     False returns the subset of the array that does not contain value as a substring. Default is True.
;    compare ........ Optional. Specifies the string comparison to use.
;                     Can have one of the following values:
;                     0 = vbBinaryCompare - Perform a binary comparison  (case not ignored).
;                     1 = vbTextCompare - Perform a textual comparison   (case ignored).
;------------------------------------------------------------------------------------------------------------------------------------------
; (c)Detlev Dalitz.20100120.
;==========================================================================================================================================


; Example Step 1.

; Create a ScriptControl object.
objVBSC = CreateObject ("MSScriptControl.ScriptControl")
objVBSC.Language = "vbscript"
objVBSC.AllowUI = @FALSE


; Example Step 2.

Message ("WB", "Next step:" : @LF : "Create WB array and display all elements in WB array.")

; WB.
; Create a WB Dim-1 array.
arrWB = ArrDimension (8)
arrWB[0] = ObjectType ("NULL", "") ; Just for demonstration.
arrWB[1] = "Monday"
arrWB[2] = "Tuesday"
arrWB[3] = "Wednesday"
arrWB[4] = "Thursday"
arrWB[5] = "Friday"
arrWB[6] = "Saturday"
arrWB[7] = "Sunday"

intDims = ArrInfo (arrWB, 0)
intElements = ArrInfo (arrWB, 1)
Terminate (intElements == 0, "Terminated.", "No elements ... nothing to do.")

; Display WB array content.
intElemLast = intElements - 1
For intElem = 0 To intElemLast
   Message ("WB Array|Element: " : intElem, "Content: " : arrWB[intElem])
Next


; Example Step 3.

Message ("WB", "Next step:" : @LF : "Create VB array from WB array and display all elements in VB array.")

; VB.
; Create VB array from WB array.
objVBSC.AddCode(: "Function My_VBS_Function (Arg)" : @LF : "My_VBS_Function = Arg" : @LF : "End Function")
arrVB = objVBSC.Run(: "My_VBS_Function", arrWB)

; WB.
intDims = ArrInfo (arrVB, 0)
intElements = ArrInfo (arrVB, 1)
Terminate (intElements == 0, "Terminated.", "No elements ... nothing to do.")

intElem = 0
ForEach arrElement In arrVB
   Message ("WB|VB Array|Element: " : intElem, "Content: " : arrElement)
   intElem = intElem + 1
Next


; Example Step 4.

; VB.
; Find all array elements which contain the letter "n".
strVBSearch = "n"
strVBInclude = "vbTrue"
strVBCompare = "vbTextCompare"
Message ("WB", "Next step:" : @LF : 'Find all elements in VB array which contain "' : strVBSearch : '"' : @LF : "and return a VB array with the result.")
objVBSC.AddCode(: "Function My_VBS_Function (Arg)" : @LF : 'My_VBS_Function = Filter(Arg,"' : strVBSearch : '",' : strVBInclude : ',' : strVBCompare : ')' : @LF : "End Function")
arrVB = objVBSC.Run(: "My_VBS_Function", arrWB)

; WB.
intDims = ArrInfo (arrVB, 0)
intElements = ArrInfo (arrVB, 1)
Terminate (intElements == 0, "Terminated.", "No elements ... nothing to do.")

intElem = 0
ForEach arrElement In arrVB
   Message ("WB|VB Array|Element: " : intElem, "Content: " : arrElement)
   intElem = intElem + 1
Next
; Result: Monday, Wednesday, Sunday.


; Example Step 5.

; VB.
; Find all array elements which do not contain the letter "n".
strVBSearch = "n"
strVBInclude = "vbFalse"
strVBCompare = "vbTextCompare"
Message ("WB", "Next step:" : @LF : 'Find all elements in VB array which do not contain "' : strVBSearch : '"' : @LF : "and return a VB array with the result.")
objVBSC.AddCode(: "Function My_VBS_Function (Arg)" : @LF : 'My_VBS_Function = Filter(Arg,"' : strVBSearch : '",' : strVBInclude : ',' : strVBCompare : ')' : @LF : "End Function")
arrVB = objVBSC.Run(: "My_VBS_Function", arrWB)

; WB.
intDims = ArrInfo (arrVB, 0)
intElements = ArrInfo (arrVB, 1)
Terminate (intElements == 0, "Terminated.", "No elements ... nothing to do.")

intElem = 0
ForEach arrElement In arrVB
   Message ("WB|VB Array|Element: " : intElem, "Content: " : arrElement)
   intElem = intElem + 1
Next
; Result: NULL (i. e. empty string), Tuesday, Thursday, Friday, Saturday.


; Example Step 6.

Message ("WB", "Ready.")
DropWild ("obj*")
Exit
;==========================================================================================================================================