Jump to content

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])
            Sleep(50)
        Next
    Next
Next

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"

^ ERROR

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

Link to comment
Share on other sites

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

has elements:

[0][0]

[0][1]

[0][2]

[1][0]

[1][1]

[1][2]

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.

Bob

Edited by YellowLab

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

Link to comment
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
 Share

  • Recently Browsing   0 members

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