Jump to content

two dimenstional aray search


Recommended Posts

How do I do a two dimensional array search?

Is there a way to load the array in on line

ie $Array[0][0] = "String0","apple"

_ArraySearch

#Include<Array.au3>

Dim $Array[6][2]

$Array[0][0] = "String0"

$Array[1] [0]= "String1"

$Array[2] [0]= "String2"

$Array[0][1] = "apple"

$Array[1] [1]= "orange"

$Array[2] [1]= "pear"

$Input = InputBox("ArraySearch Demo", "String To Find?")

If @error Then Exit

$Pos = _ArraySearch ($Array, $Input, 0, 0, 0, True)

Select

Case $Pos = -1

MsgBox(0, "Not Found", '"' & $Input & '" was not found in the array.')

Case Else

MsgBox(0, "Found", '"' & $Input & '" was found in the array at pos ' & $Pos & ".")

EndSelect

Link to comment
Share on other sites

Try this:

Dim $Array[6][2]
$Array[0][0] = "String0"
$Array[1] [0]= "String1"
$Array[2] [0]= "String2"

$Array[0][1] = "apple"
$Array[1] [1]= "orange"
$Array[2] [1]= "pear"

$Input = InputBox("ArraySearch Demo", "String To Find?")
If @error Then Exit

For $x = 0 to UBound($Array,1) -1
    For $y = 0 to Ubound($Array,2) -1
        If StringInStr($Array[$x][$y],$Input) > 0 Then
            msgbox(0,"","Item found in Array[" & $x & "][" & $y &"]")
        EndIf
    Next
Next
Edited by covaks
Link to comment
Share on other sites

Is there a way to load the array in on line

ie $Array[0][0] = "String0","apple"

Dim $Array[6][2]

$Array[0][0] = "String0"

$Array[1] [0]= "String1"

$Array[2] [0]= "String2"

$Array[0][1] = "apple"

$Array[1] [1]= "orange"

$Array[2] [1]= "pear"

Global $Array[6][2] = [["String0", "apple"], ["String1", "orange"], ["String2", "pear"]]

One "row" of data in each inner set of square brackets.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...