Jump to content
Sign in to follow this  

Help on Arrays

Recommended Posts


I am not working on a script atm. I am trying to understand arrays, here is my script:

Dim $arr[2][3]

$arr[1][1]="element 1,1"
$arr[1][2]="Element 1,2"
$arr[1][3]="element 1,3"
$arr[2][1]="Element 2,1"
$arr[2][2]="Element 2,2"
$arr[2][3]="element 2,3"

For 1 To 6 Step +1
    For $x=0 to UBound($arr) Step +1
        For $y=0 To UBound($arr, 2) Step +1
            MsgBox(1,"arrays","array contains " & $arr[$x][$y])

I just made an array with the dimensions [2][3]. Then i listed all the values in the array. I was trying to get a message box to show all the values, but I didn't get that far. This is the error I am getting:

==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$arr[1][3]="element 1,3"


>Exit code: 1 Time: 1.476

It says I am exceeding the subscript dimension range, even though I don't think I am. Can someone explain this to me.

(P.S, I am not asking for a tutorial, just a small explanation, or how to fix my script, and I will take it from there.)

Share this post

Link to post
Share on other sites

Since arrays are zero based, an array that is defined as $ar[2][3]

has elements:







The Ubound returns the number of elements for that dimension, i.e. Ubound($ar,0)=2 or Ubound($ar,1)=3, but the maximum index of that dimension is x-1: 1 or 2 respectively.


Edited by YellowLab

You can't see a rainbow without first experiencing the rain.

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