Beginner321 Posted April 3, 2009 Posted April 3, 2009 I am not working on a script atm, i just want to understand arrays. Here is my script: Dim $arr[2][3] $arr[0][0]="element 1,1" $arr[0][1]="Element 1,2" $arr[0][2]="element 1,3" $arr[1][0]="Element 2,1" $arr[1][1]="Element 2,2" $arr[1][2]="element 2,3" MsgBox(1,"","fds" & $arr[1][0]& $arr[1][1] & $arr[1][2]);I did this just to check whether the array indexes were correct For $l=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 the message box gives the value of $arr[0][0], $arr[0][1], $arr[0][2], but after that I get the error: ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: MsgBox(1,"arrays","array contains " & $arr[$x][$y]) MsgBox(1,"arrays","array contains " & ^ ERROR Can someone explain why this is happening? I just need a small explanation, not a tutorial. Thanks.
trancexx Posted April 3, 2009 Posted April 3, 2009 the index can only be between 0-2 as arrays are Zero Based. ♡♡♡ . eMyvnE
Beginner321 Posted April 3, 2009 Author Posted April 3, 2009 the index can only be between 0-2 as arrays are Zero Based.I understand that part, and I thought I fixed it, but the problem is the same. where didi make the mistake?
erik7426 Posted April 3, 2009 Posted April 3, 2009 I understand that part, and I thought I fixed it, but the problem is the same. where didi make the mistake? I can't offer an explanation but this works... Dim $arr[2][3] $arr[0][0]="element 1,1" $arr[0][1]="Element 1,2" $arr[0][2]="element 1,3" $arr[1][0]="Element 2,1" $arr[1][1]="Element 2,2" $arr[1][2]="element 2,3" MsgBox(1,"","fds" & $arr[1][0]& $arr[1][1] & $arr[1][2]);I did this just to check whether the array indexes were correct For $x=0 to UBound($arr,1) - 1 For $y=0 To UBound($arr, 2) - 1 MsgBox(1,"arrays","array contains " & $arr[$x][$y]) Sleep(50) Next Next
trancexx Posted April 3, 2009 Posted April 3, 2009 I understand that part, and I thought I fixed it, but the problem is the same. where didi make the mistake?I could just copy/paste that second post from the other thread to answer this.Just read the help file about UBound() function. ♡♡♡ . eMyvnE
Moderators SmOke_N Posted April 3, 2009 Moderators Posted April 3, 2009 (edited) I am not working on a script atm, i just want to understand arrays. Here is my script: Dim $arr[2][3] $arr[0][0]="element 1,1" $arr[0][1]="Element 1,2" $arr[0][2]="element 1,3" $arr[1][0]="Element 2,1" $arr[1][1]="Element 2,2" $arr[1][2]="element 2,3" MsgBox(1,"","fds" & $arr[1][0]& $arr[1][1] & $arr[1][2]);I did this just to check whether the array indexes were correct For $l=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 the message box gives the value of $arr[0][0], $arr[0][1], $arr[0][2], but after that I get the error: ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: MsgBox(1,"arrays","array contains " & $arr[$x][$y]) MsgBox(1,"arrays","array contains " & ^ ERROR Can someone explain why this is happening? I just need a small explanation, not a tutorial. Thanks.UBound() contains the upper bound of the index you selected. If I have $a_array[2]Then my UBound = 2 However, the max index range is 1 less than UBound(). So you would have to do: For $i = 0 To UBound($a_array) - 1Note the -1. In addition, Step 1 is standard, there is no need to use Step unless you are indexing the array backwards, then it would be Step -1, or if you are indexing the array in steps of more than one. Edited April 3, 2009 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Beginner321 Posted April 3, 2009 Author Posted April 3, 2009 I can't offer an explanation but this works... Dim $arr[2][3] $arr[0][0]="element 1,1" $arr[0][1]="Element 1,2" $arr[0][2]="element 1,3" $arr[1][0]="Element 2,1" $arr[1][1]="Element 2,2" $arr[1][2]="element 2,3" MsgBox(1,"","fds" & $arr[1][0]& $arr[1][1] & $arr[1][2]);I did this just to check whether the array indexes were correct For $x=0 to UBound($arr,1) - 1 For $y=0 To UBound($arr, 2) - 1 MsgBox(1,"arrays","array contains " & $arr[$x][$y]) Sleep(50) Next Next Thanks alot for your help. This code works, though all you changed Step +1 to simply 1. I don't really understand why though, but I'll figure it out. thanks again everyone.
Moderators SmOke_N Posted April 3, 2009 Moderators Posted April 3, 2009 Thanks alot for your help.This code works, though all you changed Step +1 to simply 1.I don't really understand why though, but I'll figure it out.thanks again everyone.I explained the "why". Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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