Jump to content

Recommended Posts

Posted

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
Posted

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.

Posted

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.

Posted

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 :D

Posted

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

Posted

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 :D

Posted

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 :D

That's correct.

$Array["Config"]["Username"] = "MyUsername"

etc.

If I knew how I'd impliment it into AutoIT myself.

Posted

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 :D
Posted

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
Posted

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.
Posted

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...

RAW 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>

PHP5 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.

Posted

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. :D

  • 3 weeks later...
Posted

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 :D !!!) The possibilities are endless, even though it is very very hard).

Good luck

  • 4 weeks later...
Posted

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 :D !!!) The possibilities are endless, even though it is very very hard).

Good luck

Ya know it's funny, I've seen the eval code in the beta documentation, but never thought to use it that way. Thanks.

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
  • Recently Browsing   0 members

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