jsteng Posted July 5, 2014 Posted July 5, 2014 (edited) GLOBAL $TimeOut[8][8],$Text[8] $Text[0] = "1000,2000,3000" $Text[1] = "1000,2000,3000" $Text[2] = "1000,2000,3000" $Text[3] = "1000,2000,3000" $Text[4] = "1000,2000,3000" $Text[5] = "1000,2000,3000" $Text[6] = "1000,2000,3000" $Text[7] = "1000,2000,3000" for $i = 0 to 7 $TimeOut[$i] = StringSplit( $Text[$i],",",2) next Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded. How do I assign an Array into an Array using StringSplit? Edited July 5, 2014 by jsteng
czardas Posted July 5, 2014 Posted July 5, 2014 (edited) You changed the code you posted. Anyway pseudo code in and you get pseudo code out. The principle is the same though. CODE DELETED Now for your modified question, here's the working solution. GLOBAL $TimeOut[8][8], $Text[8], $aTemp $Text[0] = "1000,2000,3000" $Text[1] = "1000,2000,3000" $Text[2] = "1000,2000,3000" $Text[3] = "1000,2000,3000" $Text[4] = "1000,2000,3000" $Text[5] = "1000,2000,3000" $Text[6] = "1000,2000,3000" $Text[7] = "1000,2000,3000" for $i = 0 to 7 $aTemp = StringSplit( $Text[$i], "," ,2) For $j = 0 To 2 $TimeOut[$i][$j] = $aTemp[$j] Next next ; Notice you have to give both row and column references with a two dimensional array ==> $aArray[$iRow][$iCol] and use nested loops to access individual elements within it. Edited July 5, 2014 by czardas operator64 ArrayWorkshop
jsteng Posted July 5, 2014 Author Posted July 5, 2014 I thought I can "wholesale" assign an array into an array to make it 2D Now i understand. many thanks!
czardas Posted July 5, 2014 Posted July 5, 2014 Arrays are easy once you understand the syntax. operator64 ArrayWorkshop
jsteng Posted July 6, 2014 Author Posted July 6, 2014 (edited) GLOBAL $TimeOut[8][8], $Text[8], $aTemp $Text[0] = "1000,2000,3000" $Text[1] = "1000,2000,3000" $Text[2] = "1000,2000,3000" $Text[3] = "1000,2000,3000" $Text[4] = "1000,2000,3000" $Text[5] = "1000,2000,3000" $Text[6] = "1000,2000,3000" $Text[7] = "1000,2000,3000" for $i = 0 to 7 $aTemp = StringSplit( $Text[$i], "," ,2) For $j = 0 To 2 $TimeOut[$i][$j] = $aTemp[$j] Next next ;Now how do I do something like this? _ArrayPush($TimeOut[0],$TimeOut[0][0],0) ; I am getting this error with _ArrayPush Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded. I can't do ArrayPush on multi dimensional arrays? (My purpose for the arrayPush is to rotate the data) Is it possible to pass the reference of the 2nd dimension array to a function? If so, How? Edited July 6, 2014 by jsteng
jchd Posted July 6, 2014 Posted July 6, 2014 (edited) You can't do that. First --as the help file says-- the array must be 1D. Then AutoIt unfortunately doesn't support partial indexing on multi-dimensional arrays, so $TimeOut[0] is causing the error you get. Use an ad hoc loop instead. . Edited July 6, 2014 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
jsteng Posted July 6, 2014 Author Posted July 6, 2014 The more I try to solve my multi-dimensional array problem, the more problems I encounter. GLOBAL $TimeOut[8][8], $Text[8], $aTemp $Text[0] = "0" $Text[1] = "1000,3000" $Text[2] = "1000,2000,3000" $Text[3] = "3000" $Text[4] = "2000,3000" $Text[5] = "1000,2000,3000,4000,5000,6000" $Text[6] = "0" $Text[7] = "1000" for $i = 0 to 7 $aTemp = StringSplit( $Text[$i], "," ,2) For $j = 0 To 2 $TimeOut[$i][$j] = $aTemp[$j] Next next ;Simulated _ArrayPush($TimeOut[0],$TimeOut[0][0],0) local $firstItem = $TimeOut[0][0] local $lastIndex = uBound($TimeOut[0])-1 for $i=0 to $lastIndex-1 $TimeOut[0][$i] = $TimeOut[0][$i+1] next $TimeOut[0][$lastIndex] = $firstItem UBOUND will not allow me to check on a multi-dim array... It actually does, but the way I am using above, with the 2nd dimension having different length this will not work: UBOUND($TimeOut,2) Seems that I should just put the data AS a string into the array, and have a lengthly/slower code that will convert it to an array, rotate, put it back as a string...
czardas Posted July 6, 2014 Posted July 6, 2014 (edited) jchd is correct. You don't rotate the array: Instead you rotate the calling sequence. Here's a simple example! ; GLOBAL $TimeOut[8][8], $Text[8], $aTemp $Text[0] = "0" $Text[1] = "1000,3000" $Text[2] = "1000,2000,3000" $Text[3] = "3000" $Text[4] = "2000,3000" $Text[5] = "1000,2000,3000,4000,5000,6000" $Text[6] = "0" $Text[7] = "1000" for $i = 0 to 7 ; Transform to a 2D array. $aTemp = StringSplit( $Text[$i], "," ,2) For $j = 0 To UBound($aTemp) -1 $TimeOut[$i][$j] = $aTemp[$j] Next next Local $iNextRow For $i = 0 to 99 $iNextRow = Mod($i, UBound($TimeOut)) ; Round and round we go ConsoleWrite($TimeOut[$iNextRow][0]) ; This could go inside the next loop using ==> For $j = 0 To 7 For $j = 1 To 7 If $TimeOut[$iNextRow][$j] = "" Then ExitLoop ; This comparison may not be suitable in different circumstances. ConsoleWrite("," & $TimeOut[$iNextRow][$j]) ; Comma is added back for this demonstration only. Next ConsoleWrite(@CRLF) ; Next row Next ; You can overwrite elements as you go to emulate an _ArrayPush, always keeping tabs on which row you want to treat as index 0 (virtual first row). There are many ways to do something like this. Edited July 7, 2014 by czardas operator64 ArrayWorkshop
jchd Posted July 6, 2014 Posted July 6, 2014 In addition to what czardas just posted, you can differentiate empty cells from those containing "0". Anyway $TimeOut[0] has no meaning, as in uBound($TimeOut[0])-1. AutoIt has no syntax for refering to a row or a column of a 2D (or higher dimensional) array. Either refer to the array as a whole or an individual element. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
jsteng Posted July 6, 2014 Author Posted July 6, 2014 Curious: Is there an autoit equivalent to Perl's @{$TimeOut[0]}? Or a means of getting the pointer to the 2nd dimension? That way, i can now do uBound( @{$TimeOut[0]} )
Developers Jos Posted July 6, 2014 Developers Posted July 6, 2014 You want to know the Ubound of the second dimension? From the Helpfile: UBound ( Array [, Dimension = 1] ) 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.
czardas Posted July 6, 2014 Posted July 6, 2014 (edited) A good alternative approach is to set the first column as a row entries counter like this: ; #include <Array.au3> Global $TimeOut[8][9], $Text[8], $aTemp $Text[0] = "0" $Text[1] = "1000,3000" $Text[2] = "1000,2000,3000" $Text[3] = "3000" $Text[4] = "2000,3000" $Text[5] = "1000,2000,3000,4000,5000,6000" $Text[6] = "0" $Text[7] = "1000" for $i = 0 to 7 ; Transform to a 2D array. $aTemp = StringSplit( $Text[$i], ",") ; StringSplit default flag (=0). For $j = 0 To $aTemp[0] $TimeOut[$i][$j] = $aTemp[$j] Next next _ArrayDisplay($TimeOut) ; First column gives the number of entries in each row. Edited July 7, 2014 by czardas operator64 ArrayWorkshop
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