Beginner321 Posted April 3, 2009 Posted April 3, 2009 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.)
Developers Jos Posted April 3, 2009 Developers Posted April 3, 2009 the index can only be between 0-2 as arrays are Zero Based. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
YellowLab Posted April 3, 2009 Posted April 3, 2009 (edited) 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 April 3, 2009 by YellowLab You can't see a rainbow without first experiencing the rain.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now