udfArrayJoin
str udfArrayJoin (arr, str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfArrayJoin (arrArray, strDelimiter)
objJSC = CreateObject ("MSScriptControl.ScriptControl")
objJSC.Language = "JScript"
objJSC.AllowUI = @FALSE
Switch @TRUE
Case 256 == VarType (arrArray) ; WinBatch Array.
Case ObjectTypeGet (arrArray) == "ARRAY|VARIANT" ; Variant Array
   objJSC.AddCode(: "function VB2JSArray(objVBArray){var a;try{a=new VBArray(objVBArray).toArray();}catch(e){a=new Array(objVBArray);}return a;}")
   objJSC.AddCode(: "function ArrayJoin(objVBArray,strDelimiter){return VB2JSArray(objVBArray).join(strDelimiter);}")
   strJoined = objJSC.Run(: "ArrayJoin", arrArray, strDelimiter)
   Break
Case @TRUE
   strJoined = ""
EndSwitch
Return strJoined
;..........................................................................................................................................
; This UDF "udfArrayJoin" joins all elements of an array into a string.
; The elements will be separated by the specified delimiter string.
;
; Parameter:
; arrArray ....... A one-dimensional array of strings to be searched. Array type can be WinBatch Array or Variant Array.
; strDelimiter ... A single character or a string. The elements will be separated by this delimiter.
;..........................................................................................................................................
; (c)Detlev Dalitz.20100121.
; Jim Dippner.20080221: changed VB2JSArray.
; David Wang.20060704: created VB2JSArray.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfArrayDisplayElements (arrArray, intSecondsToWait)
If ArrInfo (arrArray, 6) == 0 Then Return Message ("Array|Elements=0", "No elements ... nothing to do.")
; objWsh = ObjectCreate ("WScript.Shell")
strElems = "Array|Dim=" : ArrInfo (arrArray, 0) : "|Elements=" : ArrInfo (arrArray, 6)
arrE = ArrDimension (6)
For intD = 0 To 5
   arrE [intD] = ArrInfo (arrArray, intD)
Next
For intD = 1 To arrE [0]
   arrE [intD] = arrE [intD] - 1
Next
Switch arrE [0]
Case 1
   intElem = -1
   For intA = 0 To arrE [1]
      intElem = intElem + 1
      strElem = "|Index=" : intElem : ":" : intA
      strContent = "Content=" : arrArray [intA]
      ; If 2 == objWsh.Popup(strContent, intSecondsToWait, : strElems : strElem, 1) Then Return
      If Display (intSecondsToWait, strElems : strElem, strContent) Then If DllCall ("USER32.DLL", long : "GetAsyncKeyState", word : 27) Then Return
   Next
   Break
Case 2
   intElem = -1
   For intA = 0 To arrE [1]
      For intB = 0 To arrE [2]
         intElem = intElem + 1
         strElem = "|Index=" : intElem : ":" : intA : "," : intB
         strContent = "Content=" : arrArray [intA, intB]
         ; If 2 == objWsh.Popup(strContent, intSecondsToWait, : strElems : strElem, 1) Then Return
         If Display (intSecondsToWait, strElems : strElem, strContent) Then If DllCall ("USER32.DLL", long : "GetAsyncKeyState", word : 27) Then Return
      Next
   Next
   Break
Case 3
   intElem = -1
   For intA = 0 To arrE [1]
      For intB = 0 To arrE [2]
         For intC = 0 To arrE [3]
            intElem = intElem + 1
            strElem = "|Index=" : intElem : ":" : intA : "," : intB : "," : intC
            strContent = "Content=" : arrArray [intA, intB, intC]
            ; If 2 == objWsh.Popup(strContent, intSecondsToWait, : strElems : strElem, 1) Then Return
            If Display (intSecondsToWait, strElems : strElem, strContent) Then If DllCall ("USER32.DLL", long : "GetAsyncKeyState", word : 27) Then Return
         Next
      Next
   Next
   Break
Case 4
   intElem = -1
   For intA = 0 To arrE [1]
      For intB = 0 To arrE [2]
         For intC = 0 To arrE [3]
            For intD = 0 To arrE [4]
               intElem = intElem + 1
               strElem = "|Index=" : intElem : ":" : intA : "," : intB : "," : intC : "," : intD
               strContent = "Content=" : arrArray [intA, intB, intC, intD]
               ; If 2 == objWsh.Popup(strContent, intSecondsToWait, : strElems : strElem, 1) Then Return
               If Display (intSecondsToWait, strElems : strElem, strContent) Then If DllCall ("USER32.DLL", long : "GetAsyncKeyState", word : 27) Then Return
            Next
         Next
      Next
   Next
   Break
Case 5
   intElem = -1
   For intA = 0 To arrE [1]
      For intB = 0 To arrE [2]
         For intC = 0 To arrE [3]
            For intD = 0 To arrE [4]
               For intE = 0 To arrE [5]
                  intElem = intElem + 1
                  strElem = "|Index=" : intElem : ":" : intA : "," : intB : "," : intC : "," : intD : "," : intE
                  strContent = "Content=" : arrArray [intA, intB, intC, intD, intE]
                  ; If 2 == objWsh.Popup(strContent, intSecondsToWait, : strElems : strElem, 1) Then Return
                  If Display (intSecondsToWait, strElems : strElem, strContent) Then If DllCall ("USER32.DLL", long : "GetAsyncKeyState", word : 27) Then Return
               Next
            Next
         Next
      Next
   Next
   Break
EndSwitch
:CANCEL
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrQuote (strString, strLeft, strRight)
If strString == "" Then Return strString
If "" == strLeft
   If "" == strRight
      strQuote = """'`"
      strCleaned = StrClean (strString, strQuote, "", @FALSE, 2)
      If "" == StrClean (strQuote, strCleaned, "", @FALSE, 1)
         strQuote = '"'
         strString = StrReplace (strString, strQuote, strQuote : strQuote)
      Else
         strCleaned = StrClean (strQuote, strCleaned, "", @FALSE, 1)
         strQuote = StrSub (strCleaned, 1, 1)
      EndIf
      strLeft = strQuote
      strRight = strQuote
   EndIf
EndIf
Return strLeft : strString : strRight
;------------------------------------------------------------------------------------------------------------------------------------------
; This UDF "udfStrQuote" returns a given string enclosed in quotation characters.
;
; With strLeft="" and strRight=""
; the function chooses a winbatch quote delimiter automagically
; and doubles the quotation char in strString if necessary.
;
; With strLeft="""" and strRight=""""
; the function allows quotation without doubling of quotation char in strString.
;
; With strLeft="(* " and strRight=" *)"
; the function encloses strString in pairs of pascal comments.
;
; (c)Detlev Dalitz.20010722.20020628.20100124.
;------------------------------------------------------------------------------------------------------------------------------------------
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStringDisplay (strString, intMode)
strString = StrReplace (strString, @TAB, "@TAB")
strString = StrReplace (strString, @CR, "@CR")
strString = StrReplace (strString, @LF, "@LF")
strString = StrReplace (strString, @CRLF, "@CRLF")
If intMode Then strString = udfStrQuote (strString, "", "")
Return strString
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.

; Example 1.
; Create a WB Dim-1 array.
Message ("WB example for ArrayJoin.", "Next step:" : @LF : "Create Dim-1 WB array and display all elements in WB array.")
arrWB = ArrDimension (7)
arrWB[0] = "Monday"
arrWB[1] = "Tuesday"
arrWB[2] = "Wednesday"
arrWB[3] = "Thursday"
arrWB[4] = "Friday"
arrWB[5] = "Saturday"
arrWB[6] = "Sunday"
udfArrayDisplayElements (arrWB, 2) ; Result: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.


Message ("WB", "Next example:" : @LF : "Join all elements in array into a string. The elements will be separated by a specified separator.")
strJoiner = ""
strListJoined = "" : udfArrayJoin (arrWB, strJoiner)
Message ("Ex. 2.1, Joiner=" : udfStringDisplay (strJoiner, 1), strListJoined) ; Result: HolidayMondayTuesdayWednesdayThursdayFridaySaturdaySunday

strJoiner = " "
strListJoined = "" : udfArrayJoin (arrWB, strJoiner)
Message ("Ex. 2.2, Joiner=" : udfStringDisplay (strJoiner, 1), strListJoined) ; Result: Holiday Monday Tuesday Wednesday Thursday Friday Saturday Sunday

strJoiner = "|"
strListJoined = "" : udfArrayJoin (arrWB, strJoiner)
Message ("Ex. 2.3, Joiner=" : udfStringDisplay (strJoiner, 1), strListJoined) ; Result: Holiday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday

strJoiner = "###"
strListJoined = "" : udfArrayJoin (arrWB, strJoiner)
Message ("Ex. 2.4, Joiner=" : udfStringDisplay (strJoiner, 1), strListJoined) ; Result: Holiday###Monday###Tuesday###Wednesday###Thursday###Friday###Saturday###Sunday

strJoiner = @LF
strListJoined = "" : udfArrayJoin (arrWB, strJoiner)
Message ("Ex. 2.5, Joiner=" : udfStringDisplay (strJoiner, 0), strListJoined) ; Result: Holiday@LFMonday@LFTuesday@LFWednesday@LFThursday@LFFriday@LFSaturday@LFSunday

Exit