Sign in to follow this  
Followers 0
Bagjan Wiedus

Counting rows in an array

4 posts in this topic

Dear all,

I am using StringSplit to put 1,2 or 3 names in an array like:

$users = StringSplit ( $templine, " ")

The problem is when I want to do:

$user=$users[3]

and $users[3] is not filled/used my script exits with the following error message:

E:\srksim\autoit\domain\Add_domain_user.au3 (228) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$userlen3=StringLen($users[3])

$userlen3=StringLen(^ ERROR

Does anyone now how to count the number of rows in an array that are really filled (Ubound is counted the number of rows that exist)

Kind regards

Jan

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

StringSplit is dynamic with creating arrays. Element [0] has the amount of elements.

; The created array holds the count in $array[0]
$array = StringSplit('1|2|3|4|5', '|')
For $i = 1 To $array[0]
    MsgBox(0, '', $array[$i])
Next

StringSplit does not need UBound() to test the amount of elements.

Edit:

More text for understanding added

Ohh, and welcome to the forum. :D

Edited by MHz

Share this post


Link to post
Share on other sites

Hi,

You are using ubound() as an item; the last item will be numbered ubound()-1;

So... above is SAME as..

; The created array holds the count in $array[0]
$array = StringSplit('1|2|3|4|5', '|');6 items will be 0,1,2,3,4,5, the last will be $array(6-1)
For $i = 1 To ubound($array)-1
    MsgBox(0, '', $array[$i])
Next

(ie, after "stringsplit", ubound($array)-1=$array[0], and no such item as"$array[ubound($array)] ")

Share this post


Link to post
Share on other sites

Thanks guys, I did not now that the number of cells was stored in the first [0].

I am quite a newbie in autoit.

Kind regards,

Jan

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  
Followers 0