bboysza Posted November 1, 2005 Posted November 1, 2005 I can't for the life of me (and out of shear laziness) find a way to search a multi-dim array. Say I have an array ($avArray[key][value]) - I want to search the array for a specified VALUE (aka search criteria), and return the KEY. I guess you can tell I've read an ini section into an array... Any ideas? Thanks, Ben Ben
Danny35d Posted November 1, 2005 Posted November 1, 2005 (edited) The way I will do it is: For $x = 1 To $avArray[0][0] If $avArray[$x][1] = "Search Value" Then $Key = $avArray[$x][0] ExitLoop EndIf Next MsgBox(0, 'Search Key', 'The Key is ==> ' & $Key) Hope this will help you... Edited November 1, 2005 by Danny35d AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
bboysza Posted November 3, 2005 Author Posted November 3, 2005 The way I will do it is:For $x = 1 To $avArray[0][0] If $avArray[$x][1] = "Search Value" Then $Key = $avArray[$x][0] ExitLoop EndIf Next MsgBox(0, 'Search Key', 'The Key is ==> ' & $Key)Hope this will help you...Thank you - helps quite a bit, but I'm not exactly where I wanted to be.In this example, I'm searching to see if [$x][1] = "Search Value". Which works, but it's not a true search of the entire array. I.E., only [1] is checked against the search criteria. I could always check each one individually ([$x][1], [$x][2], [$x][3], and etc..) but I imagine somebody can clean this up for us. I'm thinking, but am not terribly talented with multi-dim's. Ben
Danny35d Posted November 3, 2005 Posted November 3, 2005 (edited) In this example, I'm searching to see if [$x][1] = "Search Value". Which works, but it's not a true search of the entire array. I.E., only [1] is checked against the search criteria. I could always check each one individually ([$x][1], [$x][2], [$x][3], and etc..)Check AutoIt help for INIREADSECTIONReturns a 2 dimensional array where element[n][0] is the key and element[n][1] is the value.Meaning [$x][1] will give you search of the entire array. If you try [$x][3] it will fail beacuse this 2 dimensional array only have 2 colums no 3 . This two dimensional array will hold all your data in [?][0] and [?][1].May be if you post an example of the ini file and the search that you are trying, or replacedthis lineIf $avArray[$x][1] = "Search Value" Thenfor this oneIf StringInStr($avArray[$x][1], "Search Value") ThenThis will make it no case sensitive... Edited November 3, 2005 by Danny35d AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
randallc Posted November 4, 2005 Posted November 4, 2005 Hi,Is this what you mean?For $Key = 0 To UBound($avArray)-1For $Value = 0 To UBound($avArray,2)-1 If $avArray[$Key][$Value] = "X" Then ExitLoop EndIfNextNextMsgBox(0, 'Search Key', 'The Index for Key is ==> ' & $Key&@CRLF&'The Index for Value is ==> ' & $Value&@CRLF&'The Cell is ==> [' & $Key-1&']['&$Value&']')Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
bboysza Posted November 11, 2005 Author Posted November 11, 2005 Hi,Is this what you mean?Best, RandallThanks Randall - just the direction I needed...Ini sample:[SectionName] Key1 = Value1 Key2 = Value2au3:$avArray = IniReadSection($IniFile, "SectionName") $Criteria = "Value1" For $Key = 0 To UBound($avArray)-1 For $Value = 0 To UBound($avArray,2)-1 If $avArray[$Key][$Value] = $Criteria Then msgbox(0, "Match Found", $Criteria &' is assigned to ' &$avArray[$Key][0]) ExitLoop Else msgbox(0, "No Match", 'Sorry, ' & $Criteria & ' was not found to be a value for any keys under queried sectioname') ExitLoop EndIf Next Next Ben
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