Dattebayo Posted July 31, 2011 Share Posted July 31, 2011 (edited) Dim $test[13][1] Hello() Func Hello() MsgBox(0,"",IsArray($test)) For $x = 1 To Ubound($test)-1 $test[$x] = "hmm" ; i want to write to the first dim. Next Endfunc How come i declare a 2D array and then cant access its 1st dimension? This cant be right. Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $test[$x] = "hmm" ^ ERROR Edited July 31, 2011 by Dattebayo Link to comment Share on other sites More sharing options...
Developers Jos Posted July 31, 2011 Developers Share Posted July 31, 2011 You have specified a second dimension so you need to use that when filling the array. Why not simply use?: Dim $test[13] 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. Link to comment Share on other sites More sharing options...
Dattebayo Posted July 31, 2011 Author Share Posted July 31, 2011 (edited) You have specified a second dimension so you need to use that when filling the array. Why not simply use?: Dim $test[13] Jos That code is just to demonstrate my problem. What I'm writing is a bigger project but Ive run into this issue. I'm writing a function to split a 1D array into a 2D array using a delimiter. However when i split the string then try to $newarray[1] = "firsthalf" then $newarray[1][1] = "Secondhalf" it errors out because of above problem. Tried Redim earlier but doesn't work with 1D -> 2D as you know. Edited July 31, 2011 by Dattebayo Link to comment Share on other sites More sharing options...
Developers Jos Posted July 31, 2011 Developers Share Posted July 31, 2011 (edited) Fine, but you either use one or 2 dimensions. Your example has 2 thus you need to use 2 when you address values in the array. EDIT: Show an example where redim doesn't as you want. Jos Edited July 31, 2011 by 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. Link to comment Share on other sites More sharing options...
Dattebayo Posted July 31, 2011 Author Share Posted July 31, 2011 Fine, but you either use one or 2 dimensions.Your example has 2 thus you need to use 2 when you address values in the array.EDIT: Show an example where redim doesn't as you want.JosI understand. I meant Redim does not preserve values if for example I fill a 1dim array then redim it to 2dim array. It'll make it 2dim but the values are gone. I tried that first so the above problem i guess was my plan B. Now i gotta come up with Plan C. anyway thanks for help. Link to comment Share on other sites More sharing options...
nAutoIT Posted August 1, 2011 Share Posted August 1, 2011 #include <array.au3> Dim $test[13][1] Hello() _ArrayDisplay($test) Func Hello() MsgBox(0,"",IsArray($test)) For $x = 1 To Ubound($test)-1 $test[$x][color="#FF0000"][0][/color] = "hmm" ; i want to write to the first dim. Next Endfunc Now the first collumn (collumn 0), except for $test[0][1], is full of "hmm". Guess you are confusing Rows, Collumns and Dimensions. You want to access the first collumn, not the first Dimension. Example: $array[4][3] has 5 Rows, 4 Collumns, 2 Dimensions. You can access single Elements, or whole Collumns or Rows, but not Dimensions. Even the Rows and Collumns are just a concept to picture a 2D Array. Example for 5D Array: $array[123][4][5][67][89] You have 124 Houses, each House has 5 Rooms, in each Room there are 6 Cabinets, with 68 Drawers per Cabinet and 90 Filecards in each Drawer. To access an information, you need to know which filecard, in which drawer, cabinet, room, house, so all 5 Dimensions. Link to comment Share on other sites More sharing options...
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