AcidicChip Posted June 7, 2006 Posted June 7, 2006 I know that you can have arrays like this... $aString[0][0] = "val" $aString[0][1] = "val" But can you have arrays like this?... $aString["Config"]["Username"] = "MyUsername" $aString["Config"]["Password"] = "MyPassword" Prolly a lame question, but thought I'd ask. Thanks in advance.
Moderators SmOke_N Posted June 7, 2006 Moderators Posted June 7, 2006 I know that you can have arrays like this... $aString[0][0] = "val" $aString[0][1] = "val" But can you have arrays like this?... $aString["Config"]["Username"] = "MyUsername" $aString["Config"]["Password"] = "MyPassword" Prolly a lame question, but thought I'd ask. Thanks in advance.Not a lame question, and has been asked several times, the answer is No unfortunately. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
forger Posted June 7, 2006 Posted June 7, 2006 (edited) hash tables?I don't know if this is what you need, but try this:http://www.autoitscript.com/forum/index.ph...ndpost&p=150781 Edited June 7, 2006 by forger
AcidicChip Posted June 7, 2006 Author Posted June 7, 2006 Not a lame question, and has been asked several times, the answer is No unfortunately.Will we ever see this happen?XML support is kinda rough with AutoIT, but if we had those type of arrays available, using XML would be WAY easier. Not just XML, but several purposes.
AcidicChip Posted June 7, 2006 Author Posted June 7, 2006 hash tables?I don't know if this is what you need, but try this:http://www.autoitscript.com/forum/index.ph...ndpost&p=150781That's pretty much what I'm looking for, but without limits. That seems to support 2 dimension, as opposed to an unlimited amoutn of dimensions.I would say that this is the first thing I've found that AutoIT lacks, that would be extremely useful.
forger Posted June 7, 2006 Posted June 7, 2006 You can add comments next to each array item e.g. ;$array[0][0] = PID $array[0][0] = $variableforpid ;or $array[0][0] = $variableforpid;=PID I guess you're right, but I'm happier with comments
ChrisL Posted June 7, 2006 Posted June 7, 2006 You can do this.. Dim $aArray[5] ReDim $aArray[UBound($aArray) + 1][5];Adjust the compare array size to accomodate new values ;Add new values to array $aArray[UBound($aArray) - 1][0] ="val1" $aArray[UBound($aArray) - 1][1] = "val2" $aArray[UBound($aArray) - 1][2] = "val3" $aArray[UBound($aArray) - 1][3] = "val4" $aArray[UBound($aArray) - 1][4] = "val5" Giving you (5) values in 1 row I use this method when I'm reading in data from a CSV file I store all of a sites location in the array, Store Number, Location, IPaddress, Address, Phone number I search the array by storenumber in the first column then get all the data from the row [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
Nomad Posted June 7, 2006 Posted June 7, 2006 You can do this.. Dim $aArray[5] ReDim $aArray[UBound($aArray) + 1][5];Adjust the compare array size to accomodate new values ;Add new values to array $aArray[UBound($aArray) - 1][0] ="val1" $aArray[UBound($aArray) - 1][1] = "val2" $aArray[UBound($aArray) - 1][2] = "val3" $aArray[UBound($aArray) - 1][3] = "val4" $aArray[UBound($aArray) - 1][4] = "val5" Giving you (5) values in 1 row I use this method when I'm reading in data from a CSV file I store all of a sites location in the array, Store Number, Location, IPaddress, Address, Phone number I search the array by storenumber in the first column then get all the data from the row I think his question is if he can name the rows and columns in the array as text instead of integers, like: $Array[Row][Column] Nomad
AcidicChip Posted June 8, 2006 Author Posted June 8, 2006 I think his question is if he can name the rows and columns in the array as text instead of integers, like: $Array[Row][Column] Nomad That's correct. $Array["Config"]["Username"] = "MyUsername" etc. If I knew how I'd impliment it into AutoIT myself.
Uten Posted June 8, 2006 Posted June 8, 2006 I know that you can have arrays like this... $aString[0][0] = "val" $aString[0][1] = "val" But can you have arrays like this?... $aString["Config"]["Username"] = "MyUsername" $aString["Config"]["Password"] = "MyPassword" Prolly a lame question, but thought I'd ask. Thanks in advance.What happend when you tried Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
jefhal Posted June 8, 2006 Posted June 8, 2006 But can you have arrays like this?... Prolly a lame question, but thought I'd ask. Thanks in advance.Prolly a lame answer, but is this what you need?:#include <array.au3> Dim $aString[2][3] Dim $Config $Config = "1" $Username = "1" $Password = "2" $aString[($Config)][($Username)] = "MyUsername" $aString[($Config)][($Password)] = "MyPassword" MsgBox(1,"test",$aString[1][1]) MsgBox(1,"test",$aString[1][2]) ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Knight Posted June 8, 2006 Posted June 8, 2006 Prolly a lame answer, but is this what you need?:#include <array.au3> Dim $aString[2][3] Dim $Config $Config = "1" $Username = "1" $Password = "2" $aString[($Config)][($Username)] = "MyUsername" $aString[($Config)][($Password)] = "MyPassword" MsgBox(1,"test",$aString[1][1]) MsgBox(1,"test",$aString[1][2]) THis is what I was going to suggest. Just turn the numbers into variables. While the variable name reflects the name you want to give it.
AcidicChip Posted June 8, 2006 Author Posted June 8, 2006 Prolly a lame answer, but is this what you need?:#include <array.au3> Dim $aString[2][3] Dim $Config $Config = "1" $Username = "1" $Password = "2" $aString[($Config)][($Username)] = "MyUsername" $aString[($Config)][($Password)] = "MyPassword" MsgBox(1,"test",$aString[1][1]) MsgBox(1,"test",$aString[1][2]) Essentially that's REALLY close, but having to declare them before hand won't work very well when parsing xml into an array. My goal was to interact with XML like PHP5's simplexml, but without the proper $Array["text"] support, it's not going to happen... Here's what PHP5's simple XML looks like... expandcollapse popupRAW XML: <rss version="2.0"> <channel> <title>USATODAY.com Money - Top Stories</title> <link>http://www.usatoday.com/money/digest.htm</link> <description>USATODAY.com Money - Top Stories (USA TODAY)</description> <language>en-us</language> <copyright>Copyright 2006, USATODAY.com, USA TODAY</copyright> <lastBuildDate>Thu, 8 Jun 2006 16:11:43 GMT</lastBuildDate> − <image> <title>USATODAY.com Money - Top Stories</title> <width>142</width> <height>18</height> <link>http://www.usatoday.com/money/digest.htm</link> − <url> http://images.usatoday.com/_common/_images/usatodaycom_135x20.gif </url> </image> − <item> <title>Stock prices plunge again</title> − <link> http://rssfeeds.usatoday.com/UsatodaycomMoney-TopStories?m=3237 </link> <pubDate>Thu, 8 Jun 2006 16:09:48 GMT</pubDate> − <description> Stock prices plunged again Thursday, forcing the New York Stock Exchange to institute trading curbs at 11:31 a.m. ET. <p><a href="http://rssfeeds.usatoday.com/~a/UsatodaycomMoney-TopStories?a=KPxv0X"><img src="http://rssfeeds.usatoday.com/~a/UsatodaycomMoney-TopStories?i=KPxv0X" border="0"></img></a></p><img src="http://rssfeeds.usatoday.com/UsatodaycomMoney-TopStories?g=3237"/> </description> − <guid isPermaLink="false"> http://www.usatoday.com/money/markets/us/2006-06-08-stocks-thurs_x.htm?csp=34 </guid> − <comments> http://www.usatoday.com/money/markets/us/2006-06-08-stocks-thurs_x.htm?csp=34&ord=1 </comments> − <feedburner:origLink> http://www.usatoday.com/money/markets/us/2006-06-08-stocks-thurs_x.htm?csp=34 </feedburner:origLink> </item> − <item> <title>Cisco's CEO Chambers to take on chairman duties</title> − <link> http://rssfeeds.usatoday.com/UsatodaycomMoney-TopStories?m=3238 </link> <pubDate>Thu, 8 Jun 2006 15:36:06 GMT</pubDate> − <description> Network equipment maker Cisco Systems said Chief Executive John Chambers will become chairman of the company when current Chairman ... <p><a href="http://rssfeeds.usatoday.com/~a/UsatodaycomMoney-TopStories?a=2ctRSK"><img src="http://rssfeeds.usatoday.com/~a/UsatodaycomMoney-TopStories?i=2ctRSK" border="0"></img></a></p><img src="http://rssfeeds.usatoday.com/UsatodaycomMoney-TopStories?g=3238"/> </description> − <guid isPermaLink="false"> http://www.usatoday.com/money/industries/technology/2006-06-08-cisco_x.htm?csp=34 </guid> − <comments> http://www.usatoday.com/money/industries/technology/2006-06-08-cisco_x.htm?csp=34&ord=2 </comments> − <feedburner:origLink> http://www.usatoday.com/money/industries/technology/2006-06-08-cisco_x.htm?csp=34 </feedburner:origLink> </item> </channel> </rss> expandcollapse popupPHP5 SIMPLE XML: Array ( [@attributes] => Array ( [version] => 2.0 ) [channel] => Array ( [title] => USATODAY.com Money - Top Stories [link] => http://www.usatoday.com/money/digest.htm [description] => USATODAY.com Money - Top Stories (USA TODAY) [language] => en-us [copyright] => Copyright 2006, USATODAY.com, USA TODAY [lastBuildDate] => Thu, 8 Jun 2006 16:11:43 GMT [image] => Array ( [title] => USATODAY.com Money - Top Stories [width] => 142 [height] => 18 [link] => http://www.usatoday.com/money/digest.htm [url] => http://images.usatoday.com/_common/_images/usatodaycom_135x20.gif ) [item] => Array ( [0] => Array ( [title] => Stock prices plunge again [link] => http://rssfeeds.usatoday.com/UsatodaycomMoney-TopStories?m=3237 [pubDate] => Thu, 8 Jun 2006 16:09:48 GMT [description] => Stock prices plunged again Thursday, forcing the New York Stock Exchange to institute trading curbs at 11:31 a.m. ET. <p><a href="http://rssfeeds.usatoday.com/~a/UsatodaycomMoney-TopStories?a=KPxv0X"><img src="http://rssfeeds.usatoday.com/~a/UsatodaycomMoney-TopStories?i=KPxv0X" border="0"></img></a></p><img src="http://rssfeeds.usatoday.com/UsatodaycomMoney-TopStories?g=3237"/> [guid] => http://www.usatoday.com/money/markets/us/2006-06-08-stocks-thurs_x.htm?csp=34 [comments] => http://www.usatoday.com/money/markets/us/2006-06-08-stocks-thurs_x.htm?csp=34&ord=1 ) [1] => Array ( [title] => Cisco's CEO Chambers to take on chairman duties [link] => http://rssfeeds.usatoday.com/UsatodaycomMoney-TopStories?m=3238 [pubDate] => Thu, 8 Jun 2006 15:36:06 GMT [description] => Network equipment maker Cisco Systems said Chief Executive John Chambers will become chairman of the company when current Chairman ... <p><a href="http://rssfeeds.usatoday.com/~a/UsatodaycomMoney-TopStories?a=2ctRSK"><img src="http://rssfeeds.usatoday.com/~a/UsatodaycomMoney-TopStories?i=2ctRSK" border="0"></img></a></p><img src="http://rssfeeds.usatoday.com/UsatodaycomMoney-TopStories?g=3238"/> [guid] => http://www.usatoday.com/money/industries/technology/2006-06-08-cisco_x.htm?csp=34 [comments] => http://www.usatoday.com/money/industries/technology/2006-06-08-cisco_x.htm?csp=34&ord=2 ) ) ) ) You can see how much easier the XML data or any data for that matter would be to work with if we had that kind of array support. We could easily loop thru items, get values, etc.
Uten Posted June 8, 2006 Posted June 8, 2006 Just a thougth from the top of my mind. I think I have seen a dll version of the awk interpreter. awk use this kind of (in awk it is the only kind) arrays. You might be able to use something like that to get what you want. As I said, just a quick though. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
randall Posted June 28, 2006 Posted June 28, 2006 Hi, I suggest you check out the new (beta) and extremely powerful functions called Assign and Eval. They allow you to instantiate variables that you don't know the name of, and then call variables of which you have the name inside a string. This in conjunction with file i/o essentially allows your code to code (It's automated programming !!!) The possibilities are endless, even though it is very very hard). Good luck
AcidicChip Posted July 22, 2006 Author Posted July 22, 2006 Hi, I suggest you check out the new (beta) and extremely powerful functions called Assign and Eval. They allow you to instantiate variables that you don't know the name of, and then call variables of which you have the name inside a string.This in conjunction with file i/o essentially allows your code to code (It's automated programming !!!) The possibilities are endless, even though it is very very hard).Good luckYa know it's funny, I've seen the eval code in the beta documentation, but never thought to use it that way. Thanks.
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