;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfArrayLocateRow (arrDim2, anySearchValue, intRowStart, intColumn) ; Prepare a dimension less output array to collect possible hits, will be redim'ed later in the find loop. arrOut = ArrDimension (0) ; Will become a dim-1 array. arrResult = ArrDimension (2) arrResult [0] = intRowStart ; Restrict search area to the given start values. arrResult [1] = intColumn While @TRUE arrResult = ArrayLocate (arrDim2, anySearchValue, arrResult[0], arrResult[1]) If arrResult[0] == -1 Then Break If arrResult[1] == intColumn ; We only need a hit within the search column. intOutLast = ArrInfo (arrOut, 1) ArrayRedim (arrOut, intOutLast + 1) ; Redim the output array. Add one new row. arrOut[intOutLast] = arrResult[0] ; We only need the current row index of the search array. EndIf arrResult[1] = arrResult[1] + 1 ; Skip this hit. EndWhile Return arrOut ;.......................................................................................................................................... ; This UDF "udfArrayLocateRow" searches for a given value within a given dim-2 array. ; The search runs from the given start row to the last row and is restricted to the given column. ; ; If the search value could not be located, then the return value is a valid dim-0 array with no elements. ; If the search was successful, then the return value is a dim-1 array. ; Each element contains a row number, which points to the corresponding row of the given data array. ; ; (c)Detlev Dalitz.20110225. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. ;------------------------------------------------------------------------------------------------------------------------------------------ ; Set data array values for this example. arrData = ArrDimension (25, 3) arrData[01, 0] = "Amsterdam" ; city arrData[01, 1] = "Europe" ; continent arrData[01, 2] = "Eberhard" ; name arrData[02, 0] = "Berlin" ; city arrData[02, 1] = "Europe" ; continent arrData[02, 2] = "Klaus" ; name arrData[07, 0] = "New York" ; city arrData[07, 1] = "America" ; continent arrData[07, 2] = "Michael" ; name arrData[11, 0] = "London" ; city arrData[11, 1] = "Europe" ; continent arrData[11, 2] = "Boris" ; name arrData[14, 0] = "Seattle" ; city arrData[14, 1] = "America" ; continent arrData[14, 2] = "Michael" ; name arrData[24, 0] = "Paris" ; city arrData[24, 1] = "Europe" ; continent arrData[24, 2] = "Bertrand" ; name ;------------------------------------------------------------------------------------------------------------------------------------------ ; Find items with the text "America" in column = 1, starting from row = 5, will give two hits. intTest = 1 intSearchRowStart = 5 intSearchColumn = 1 strSearchValue = "America" arrRows = udfArrayLocateRow (arrData, strSearchValue, intSearchRowStart, intSearchColumn) GoSub DisplayMessage ; Find items with the text "America" in column = 1, starting from row = 10, will give one hit. intTest = 2 intSearchRowStart = 10 intSearchColumn = 1 strSearchValue = "America" arrRows = udfArrayLocateRow (arrData, strSearchValue, intSearchRowStart, intSearchColumn) GoSub DisplayMessage ; Find items with the text "Michael" in column = 2, starting from row = 7, will give two hits. intTest = 3 intSearchRowStart = 7 intSearchColumn = 2 strSearchValue = "Michael" arrRows = udfArrayLocateRow (arrData, strSearchValue, intSearchRowStart, intSearchColumn) GoSub DisplayMessage ; Find items with the text "Michael" in column = 0, starting from row = 0, will give no hit. intTest = 4 intSearchRowStart = 0 intSearchColumn = 0 strSearchValue = "Michael" arrRows = udfArrayLocateRow (arrData, strSearchValue, intSearchRowStart, intSearchColumn) GoSub DisplayMessage ; Find items with the text "Europe" in column = 1, starting from row = 10, will give two hits. intTest = 5 intSearchRowStart = 10 intSearchColumn = 1 strSearchValue = "Europe" arrRows = udfArrayLocateRow (arrData, strSearchValue, intSearchRowStart, intSearchColumn) GoSub DisplayMessage ; Find items with the text "" in column = 0, starting from row = 0, will give no hit. intTest = 6 intSearchRowStart = 0 intSearchColumn = 0 strSearchValue = "" arrRows = udfArrayLocateRow (arrData, strSearchValue, intSearchRowStart, intSearchColumn) GoSub DisplayMessage :CANCEL Exit ;------------------------------------------------------------------------------------------------------------------------------------------ :DisplayMessage strMsgTitle = "Demo udfArrayLocateRow|Test " : intTest intElems = ArrInfo (arrRows, 1) If !intElems Pause (strMsgTitle, "Nothing found.") Else intLast = intElems - 1 For intR = 0 To intLast strMsgText = "Hit = " : 1 + intR : " of " : 1 + intLast strMsgText = strMsgText : @LF : @LF : "Search Value = " : strSearchValue strMsgText = strMsgText : @LF : "Seach Row Start = " : intSearchRowStart strMsgText = strMsgText : @LF : "Search Column = " : intSearchColumn strMsgText = strMsgText : @LF : @LF : "Row Found = " : arrRows[intR] Pause (strMsgTitle, strMsgText) Next EndIf Return ; from GoSub. ;------------------------------------------------------------------------------------------------------------------------------------------