JSands Posted August 15, 2012 Share Posted August 15, 2012 (edited) These things have always made my head hurt for some reason, and I can't seem to figure this out. I want an array to hold a list of names, and each name has 3 attributes that go with it, Address, Phone#, and Zip Code. So the first element might look like: ["John"] ["987 Foo St"] [5555555555] [90210] I then need to be able to search through the first element, the Name, until a match was found, then extract the 3 corresponding attributes Psuedocode: Local $MyArray[x][x][x][x] = ? Local $SearchingFor = "Fred" Local $Address Local $Phone Local $Zip For $i = 0 To 20 ;I know how many names are in the list If $SearchingFor = $MyArray[$i] Then $Address = $MyArray[$i][AddressIsHere][][] $Phone = $MyArray[$i][][PhoneIsHere][] $Zip = $MyArray[$i][][][ZipIsHere] ExitLoop Next I'm probably way off target, or completely misunderstanding how MD arrays work. Am I even close, and if so, does anyone have a short example? The wiki just confused me, but that's probably because it used all numbers instead of different categories. The key point is I need a way to have four variables that are tied to each other with a way to search through the first one with a for/to loop in order to extract the other three. I have well over 500 sets of data to sort through, and I'd rather not make a Select-Case/If-Then loop that big with over 500 separate variables. Edited August 15, 2012 by JSands Link to comment Share on other sites More sharing options...
Malkey Posted August 15, 2012 Share Posted August 15, 2012 Here is an example of a 2D multi-dimensional array. #include <Array.au3> Local $MyArray[20][4] = _ [["Name", "Address", "Phone#", "Zip Code"], _ ["John", "987 Foo St", "5555555555", 90210], _ ["Fred", "223 Fi St", "5555555556", 90211]] _ArrayDisplay($MyArray) Local $SearchingFor = "Fred" Local $Address Local $Phone Local $Zip Local $iIndex = _ArraySearch($MyArray, $SearchingFor) MsgBox(0, "Found " & $SearchingFor & " @ index " & $iIndex, $MyArray[$iIndex][0] & " " & $MyArray[$iIndex][1] & " " & $MyArray[$iIndex][2] & " " & $MyArray[$iIndex][3]) Link to comment Share on other sites More sharing options...
czardas Posted August 15, 2012 Share Posted August 15, 2012 You must read the wiki article about arrays.Dim $MyArray[5][4] = _ [["John","897 Foo St","5555555555","90210"], _ ["Jim","53 FooBar St","3333333333","98642"], _ ["Paul","1 Foo Ln","2222222222","67361"], _ ["Fred","356 Bar St","4444444444","23562"], _ ["Andy","16 Bar Ave","1111111111","48036"]] $SearchingFor = "Fred" For $i = 0 To UBound ($MyArray) -1 ; Array is zero based If $MyArray[$i][0] = $SearchingFor Then ExitLoop ; No need to carry on searching Next Dim $Address, $Phone, $Zip If $i < UBound ($MyArray) Then ; The loop was terminated on finding a match $Address = $MyArray[$i][1] $Phone = $MyArray[$i][2] $Zip = $MyArray[$i][3] ConsoleWrite($SearchingFor & "|" & $Address & "|" & $Phone & "|" & $Zip) EndIf operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
JSands Posted August 15, 2012 Author Share Posted August 15, 2012 (edited) Here is an example of a 2D multi-dimensional array. Perfect example, now I get it. I swear, every example I've seen uses a bunch of integers that makes it difficult to follow. That _ArrayDisplay is a cool function I hadn't seen yet, really made it simple to see what happened and what I need to do. Thanks again! You must read the wiki article about arrays. As mentioned in my first post, I read that and the part about MD Arrays confused me. I saw this: Local $arr[3][3][3][3] = [[[[1, 2, 3],[2, 3, 4],[3, 4, 5]], _ [[1, 2, 3],[2, 3, 4],[3, 4, 5]],[[1, 2, 3],[2, 3, 4],[3, 4, 5]]], _ [[[1, 2, 3],[2, 3, 4],[3, 4, 5]],[[1, 2, 3],[2, 3, 4],[3, 4, 5]], _ [[1, 2, 3],[2, 3, 4],[3, 4, 5]]],[[[1, 2, 3],[2, 3, 4],[3, 4, 5]], _ [[1, 2, 3],[2, 3, 4],[3, 4, 5]],[[1, 2, 3],[2, 3, 4],[3, 4, 5]]]] And had no idea which set was being assigned and to where. Malkey's example, and the one you posted as well, are much more easy to follow than the wiki. Thanks again to you both. Edited August 15, 2012 by JSands Link to comment Share on other sites More sharing options...
spudw2k Posted August 15, 2012 Share Posted August 15, 2012 (edited) well done, another aspiring autoit scripter joins the assembly. Edited August 15, 2012 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
czardas Posted August 15, 2012 Share Posted August 15, 2012 Yes that example is a four dimensional array (which is perhaps a little hard to imagine). You only need a two dimensional array. I use _ArrayDisplay a lot to check that the contents of a one or two dimensional array are correct. You will become more familiar with arrays with practice. Happy to assist. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now