So I wrote this based on the standard 1d arraySearch()
Example use below###User Defined Function###
_ArraySearch2d
###Description###
Finds an entry within a Two-dimensional array.
###Syntax###
_ArraySearch2d($avArray, $vWhat2Find, $i_RowStart = 0, $i_RowEnd = 0, $i_ColumnStart = -1, $i_ColumnEnd = -1, $iCaseSense = 0,
$fPartialSearch = False)
###Parameters###
@@ParamTable@@
$avArray = The array to search
$vWhatToFind = What to search $avArray for
$i_RowStart (Optional) = Start array index for search, normally set to 0 or 1. If omitted it is set to 0
$i_RowEnd (Optional) = End array index for search. If omitted or set to 0 it is set to Ubound($avArray)-
$i_ColumnStart (Optional) = First Column to start the search from Default value is -1 start at 0 column
$i_ColumnEnd (Optional) = Last Column to allow in the search Default value is -1 search all columns
$iCaseSense (Optional) = If set to 1 then search is case sensitive
$fPartialSearch (Optional) = If set to True then executes a partial search. If omitted it is set to False
@@End@@
###ReturnValue###
@@ReturnTable@@
On Success - Returns an array of the positions of the item in a 2darray. $ret[0] = the Row number $ret[1] = the Column number
On Failure - Returns -1 and sets @Error on Errors.
@Error=1 $avArray is not an array
@Error=2 $avArray is a 1dimensional not a 2d array
@Error=3 $i_RowEnd is greater than UBound($avArray)-1
@Error=4 $i_RowEnd is less than 0
@Error=5 $i_ColumnStart is greater than UBound($avArray,2)-1 (the amount of columns)
@Error=6 $i_ColumnStart is less than 0 (columns)
@Error=7 User $i_RowStart value is greater than the $i_RowEnd value
@Error=8 User $i_ColumnStart value is greater than the $i_ColumnEnd value
@Error=9 User specified $i_ColumnStart value is greater than UBound($avArray,2)-1 (the amount of columns)
@Error=10 $iCaseSense was invalid. (Must be 0 or 1)
@Error=11 $vWhatToFind was not found in $avArray
@@End@@
###Remarks###
None.
#include <array.au3> #include <array2.au3> ;Example Local $my2dArray[5][5] $my2dArray[0][0] = "Name" $my2dArray[0][1] = "Points" $my2dArray[0][2] = "Town" $my2dArray[0][3] = "Colour" $my2dArray[0][4] = "Manufacturer" $my2dArray[1][0] = "Peter" $my2dArray[1][1] = "12" $my2dArray[1][2] = "Peterborough" $my2dArray[1][3] = "Green" $my2dArray[1][4] = "Vauxhall" $my2dArray[2][0] = "Alan" $my2dArray[2][1] = "23" $my2dArray[2][2] = "Stamford" $my2dArray[2][3] = "Blue" $my2dArray[2][4] = "Ford" $my2dArray[3][0] = "Sarah" $my2dArray[3][1] = "30" $my2dArray[3][2] = "Cambridge" $my2dArray[3][3] = "Yellow" $my2dArray[3][4] = "Volkswagen" $my2dArray[4][0] = "Jane" $my2dArray[4][1] = "52" $my2dArray[4][2] = "Northampton" $my2dArray[4][3] = "Pink" $my2dArray[4][4] = "Fiat" _ArrayDisplay($my2dArray, "Visual representation of $my2dArray") $what2Find = "Volkswagen" $pos = $pos = _ArraySearch2d($my2dArray, $what2Find, 0, 0, -1, -1, 0, False) If Not @error Then MsgBox(0, "", $what2Find & " is found in row " & $pos[0] & " Column " & $pos[1] & @CRLF & _ "$my2dArray[" & $pos[0] & "][" & $pos[1] & "] = " & $what2Find) Else MsgBox(0, "", "Error " & @error) EndIf
Edit: Edited with standard variable names
Attached Files
Edited by ChrisL, 18 November 2007 - 09:28 PM.






