;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfArrayAskRow (strTitle, arrArray, intSortMode, intSelectMode, intAskMode, intViewMode) intSortMode = Max (@UNSORTED, Min (@SORTED, intSortMode)) intSelectMode = Max (@SINGLE, Min (@EXTENDED, intSelectMode)) intAskMode = Max (0, Min (1, intAskMode)) chrDelimItem = @TAB chrDelimRow = @LF intDimMin = 1 intDimMax = 2 intDim = ArrInfo (arrArray, 0) If intDim > intDimMax Then Return "" If intDim < intDimMin Then Return "" For intElem = 1 To intDimMax intE%intElem% = Max (0, ArrInfo (arrArray, intElem) - 1) Next strAskList = "" For intD1 = 0 To intE1 strRow = "" For intD2 = 0 To intE2 strIndexList = "" For intElem = 1 To intDim strIndexList = ItemInsert (intD%intElem%, -1, strIndexList, ",") Next If !!VarType (arrArray [%strIndexList%]) strRow = strRow : chrDelimItem : arrArray [%strIndexList%] Else strRow = strRow : chrDelimItem EndIf Next If intViewMode Then strRow = strRow : chrDelimItem : intD1 ; Add Row number at end of strRow. strAskList = ItemInsert (StrSub (strRow, 2, -1), -1, strAskList, chrDelimRow) Next strResultList = "" strRowList = AskItemlist (strTitle, strAskList, chrDelimRow, intSortMode, intSelectMode) Select intAskMode Case 0 intCount = ItemCount (strRowList, chrDelimRow) For intElem = 1 To intCount strRowItem = ItemExtract (intElem, strRowList, chrDelimRow) strRowNum = ItemExtract (-1, strRowItem, chrDelimItem) strResultList = ItemInsert (strRowNum, -1, strResultList, chrDelimRow) Next Break Case 1 strResultList = strRowList Break EndSelect :CANCEL Return strResultList ;------------------------------------------------------------------------------------------------------------------------------------------ ; Parameters: ; strTitle = Title of the AskItemList box. ; arrArray = A dim-1 resp. dim-2 array variable. ; intSortMode = @sorted for an alphabetic list. ; intSortMode = @unsorted to display the list of items as is. ; intSelectMode = @single to limit selection to one item. ; intSelectMode = @multiple to allow selection of more than one item. ; intSelectMode = @extended to allow selection of multiple items by extending the selection with the mouse or shift key. ; intAskMode = 0 to return a list of selected array strRow index/es delimited by @LF character. ; intAskMode = 1 to return a list of selected array strRow/s delimited by @LF character. ; intViewMode = 0 to display the row line without index number at end of the rowl line. ; intViewMode = 1 to display the index number at end of the rowl line. ; ; If array dimension is not in the allowed range (1..2) then this UDF returns an empty string "". ; ; The function IntControl (63, p1, p2, p3, p4) can be used to set the display coordinates for AskItemList. ; (IntControl 63 can be useful to cut resp. hide the rightmost array column item while displaying the AskItemList box.) ; ; Detlev Dalitz.20020521.20090508.20090531.20100122. ;------------------------------------------------------------------------------------------------------------------------------------------ #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. ; Create dim-2 test Array with intDim1 strRows and intDim2 columns intDim1 = 4 intDim2 = 4 arrArray = ArrDimension (intDim1, intDim2) arrArray [0, 0] = "Mickey" arrArray [0, 1] = "Mouse" arrArray [0, 2] = 11 arrArray [0, 3] = "MM" arrArray [1, 0] = "Goofy" arrArray [1, 1] = "Dog" arrArray [1, 2] = 22 arrArray [1, 3] = "GD" arrArray [2, 0] = "Carlo" arrArray [2, 1] = "Cat" arrArray [2, 2] = 33 arrArray [2, 3] = "CC" arrArray [3, 0] = "Dagobert" arrArray [3, 1] = "Duck" arrArray [3, 2] = 44 arrArray [3, 3] = "DD" ; Another testcase. ; Create dim-1 test array with intDim1 Rows ;intDim1 = 4 ;arrArray = ArrDimension (intDim1) ; ;arrArray [0] = "Mickey" ;arrArray [1] = "Goofy" ;arrArray [2] = "Carlo" ;arrArray [3] = "Dagobert" strMsgTitle = "Demo: udfArrayAskRow (strTitle, arrArray, intSortMode, intSelectMode, intAskMode)" intSortMode = @UNSORTED ;intSortMode = @SORTED ; Test 1.1 strTitle = "Test 1.1 - Select single Array Row (Result: Index)" strRowList = udfArrayAskRow (strTitle, arrArray, intSortMode, @SINGLE, 0, 1) strMsgText = strRowList strMsgText = strTitle : @LF : @LF : strMsgText : @LF Message (strMsgTitle, strMsgText) ; Test 1.2 strTitle = "Test 1.2 - Select single Array Row (Result: Row)" strRowList = udfArrayAskRow (strTitle, arrArray, intSortMode, @SINGLE, 1, 1) strMsgText = strRowList strMsgText = strTitle : @LF : @LF : strMsgText Message (strMsgTitle, strMsgText) ; Test 2.1 strTitle = "Test 2.1 - Select multiple Array Row/s (Result: Index/es)" strMsgText = udfArrayAskRow (strTitle, arrArray, intSortMode, @MULTIPLE, 0, 1) strMsgText = strTitle : @LF : @LF : strMsgText Message (strMsgTitle, strMsgText) ; Test 2.2 strTitle = "Test 2.2 - Select multiple Array Row/s (Result: Row/s)" strMsgText = udfArrayAskRow (strTitle, arrArray, intSortMode, @MULTIPLE, 1, 1) strMsgText = strTitle : @LF : @LF : strMsgText Message (strMsgTitle, strMsgText) ; Test 3.1 strTitle = "Test 3.1 - Select extended Array Row/s (Result: Index/es)" strMsgText = udfArrayAskRow (strTitle, arrArray, intSortMode, @EXTENDED, 0, 1) strMsgText = strTitle : @LF : @LF : strMsgText Message (strMsgTitle, strMsgText) ; Test 3.2 strTitle = "Test 3.2 - Select extended Array Row/s (Result: Row/s)" strMsgText = udfArrayAskRow (strTitle, arrArray, intSortMode, @EXTENDED, 1, 1) strMsgText = strTitle : @LF : @LF : strMsgText Message (strMsgTitle, strMsgText) ; Test 3.1 strTitle = "Test 4.1 - Select extended Array Row/s (Result: Row/s), Viewmode=0" strMsgText = udfArrayAskRow (strTitle, arrArray, intSortMode, @EXTENDED, 1, 0) strMsgText = strTitle : @LF : @LF : strMsgText Message (strMsgTitle, strMsgText) ; You can run the tests with "intSortMode = @SORTED" too. :CANCEL Exit