Jump to content
Sign in to follow this  
Zepx

Assigning Array

Recommended Posts

Zepx

Hi,

I'm pretty new to AutoIt scripting.

Ok, my question is, how can I do this?

For $i = 0 To 5 Step +1
    $readline = FileReadLine($file, $i)
    $columns = StringSplit($readline, "|")
    $names[$i] = $columns[1]
    $age[$i] = $columns[2]
Next

my problem with this code gives me

Error: Expected a "=" operator in assignment statement

I have no idea how I can solve this problem. Basically this codes reads from $file every line and then assigns name and age in to a separate variable which indexes from 0 to 5.

Share this post


Link to post
Share on other sites
hearurscream

Take the plus sign out of your For statement.


Infinity is a floorless room without walls or ceiling.Anyone who cannot cope with mathematics is not fully human. At best he is a tolerable subhuman who has learned to wear shoes, bathe, and not make messes in the house.

Share this post


Link to post
Share on other sites
Zepx

Thanks for the info, but that doesn't solve my problem for the array assigning, since it gives me that error.

Share this post


Link to post
Share on other sites
hearurscream

Can you give us a line number, or perhaps include the rest of the error statement?


Infinity is a floorless room without walls or ceiling.Anyone who cannot cope with mathematics is not fully human. At best he is a tolerable subhuman who has learned to wear shoes, bathe, and not make messes in the house.

Share this post


Link to post
Share on other sites
Zepx

Ah, sorry bout that.

The problem given when runned is at this line:

$names[$i] = $columns[1]
$age[$i] = $columns[2]

Share this post


Link to post
Share on other sites
hearurscream

Well I don't see a problem in your script, but can you post the whole code?


Infinity is a floorless room without walls or ceiling.Anyone who cannot cope with mathematics is not fully human. At best he is a tolerable subhuman who has learned to wear shoes, bathe, and not make messes in the house.

Share this post


Link to post
Share on other sites
Zepx

Yeah sure. The coding above I used was for testing.

The original code is for this. Hope it helps.

clicker.au3

Share this post


Link to post
Share on other sites
randallc

Yeah sure. The coding above I used was for testing.

The original code is for this. Hope it helps.

hi, maybe;

local $account[$countlines],$password[$countlines] 
For $i = 0 To $countlines
    $readline = FileReadLine($file, $i)
    $columns = StringSplit($readline, "|")
    $account[$i] = $columns[1]
    $password[$i] = $columns[2]
Next
I can't see that you have declared size of array anywhere? (see helpfile on Arrays)

best, Randall

Share this post


Link to post
Share on other sites
Zepx

yeah, it was my mistake for not declaring the array size.

@randallc,

I used your method, however it seems that I'm getting

Array variable has incorrect number of subscripts or subscript dimension range exceeded. Any ideas? I searched the forum, but I don't understand...

Share this post


Link to post
Share on other sites
randallc

yeah, it was my mistake for not declaring the array size.

@randallc,

I used your method, however it seems that I'm getting

Array variable has incorrect number of subscripts or subscript dimension range exceeded. Any ideas? I searched the forum, but I don't understand...

Hi, Sorry,

probably;

local $account[$countlines+1],$password[$countlines+1]
Randall

Share this post


Link to post
Share on other sites
Zepx

Hmm.. it still gives the same error. However, I changed it from using the loop For to While... in this case the expression is < $countlines. It works nicely =)...

I don't understand the usage of Ubound and those _FileReadToArray thingy... many of the other topics uses them. This is my first script.

Btw, thanks for your help randallc!

Share this post


Link to post
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
Sign in to follow this  

×