;---------------------------------------------------------------------------------------------------------------------- #DefineFunction udfArrayItemize (arrArray, strDelimiter) If !ArrInfo (arrArray, -1) Then Return "" ; No array. If !ArrInfo (arrArray, 6) Then Return "" ; No elements. If ArrInfo (arrArray, 0) > 1 Then Return "" ; Too much dimensions. strItemList = "" intHigh = Max (ArrInfo (arrArray, 1) - 1, 0) intLow = 0 For intElem = intLow To intHigh If !!VarType (arrArray [intElem]) strItemList = strItemList : strDelimiter : arrArray [intElem] Else strItemList = strItemList : strDelimiter EndIf Next Return StrSub (strItemList, 2, -1) ;---------------------------------------------------------------------------------------------------------------------- ; This UDF "udfArrayItemize" converts a given dim-1 array into an itemlist ; with each item separated by delimiter character. ; ; Example: strMyItemList = udfArrayItemize (arrMyArray, @TAB) ; Creates an itemList from array. ; ; Note: ; This UDF supports only dim-1 array. ; An array element which is not initialized has a Vartype=0 (undefined). ; Therefore an empty item will be appended to target itemlist. ; ; Detlev Dalitz.20020718.20090508.20090516. ;---------------------------------------------------------------------------------------------------------------------- #EndFunction ;---------------------------------------------------------------------------------------------------------------------- ; Test. strMsgTitle = "Demo: udfArrayItemize (arrArray, strDelimiter)" strFilename = IntControl (1004, 0, 0, 0, 0) ; We use this file as test input. ; Count lines. intLineCount = 0 hdlFR = FileOpen (strFilename, "READ") While @TRUE If FileRead (hdlFR) == "*EOF*" Then Break intLineCount = intLineCount + 1 EndWhile hdlFR = FileClose (hdlFR) ; Define a dim-1 array. arrMyArray = ArrDimension (intLineCount) Message (strMsgTitle, "MyArray contains " : ArrInfo (arrMyArray, 6) : " elements.") ; Fill the array with data from this file. intLineCount = 0 hdlFR = FileOpen (strFilename, "READ") While @TRUE strLine = FileRead (hdlFR) If strLine == "*EOF*" Then Break arrMyArray [intLineCount] = strLine intLineCount = intLineCount + 1 EndWhile hdlFR = FileClose (hdlFR) ; Convert the array to an itemlist. strMyItemList = udfArrayItemize (arrMyArray, @TAB) intItemCount = ItemCount (strMyItemList, @TAB) Message (strMsgTitle, "MyItemList contains " : intItemCount : " items.") ; Display result. IntControl (28, 1, 0, 0, 0) IntControl (63, 100, 100, 900, 900) AskItemlist (strMsgTitle, strMyItemList, @TAB, @UNSORTED, @SINGLE) :CANCEL Exit