myt Posted July 18, 2007 Share Posted July 18, 2007 I'm trying to assign an array of words returned by StringSplit to another 2D array. Here's what I did: Dim $wordArray[8][64] $wordArray[1] = StringSplit(...) When I try to access something in the array like $wordCount = $wordArray[1][0] it gives an error about incorrect number of subscripts or dimension exceeded. Link to comment Share on other sites More sharing options...
DW1 Posted July 18, 2007 Share Posted July 18, 2007 Did you DIM it as a 2D array? AutoIt3 Online Help Link to comment Share on other sites More sharing options...
myt Posted July 18, 2007 Author Share Posted July 18, 2007 Did you DIM it as a 2D array? That's what I did, didn't I? Dim $wordArray[8][64] Link to comment Share on other sites More sharing options...
Valuater Posted July 18, 2007 Share Posted July 18, 2007 Maybe... $days = StringSplit("Sun,Mon,Tue,Wed,Thu,Fri,Sat", ",") ;$days[1] contains "Sun" ... $days[7] contains "Sat" for $x = 1 to $days[0] ; $days[0] = the total MsgBox(0x0, "Day", $days[$x], 2) Next 8) Link to comment Share on other sites More sharing options...
myt Posted July 18, 2007 Author Share Posted July 18, 2007 Maybe... $days = StringSplit("Sun,Mon,Tue,Wed,Thu,Fri,Sat", ",") ;$days[1] contains "Sun" ... $days[7] contains "Sat" for $x = 1 to $days[0] ; $days[0] = the total MsgBox(0x0, "Day", $days[$x], 2) Next 8)I'm aware of how StringSplit works, but I'm trying to store an array of splitted strings. For example, $wordArray[0] would contain a list of words $wordArray[1] would contain another list of words and $wordArray[1][0] would be the number of words in $wordArray[1] Link to comment Share on other sites More sharing options...
SadBunny Posted July 18, 2007 Share Posted July 18, 2007 Poster seems to want to put an array into another array element (issue doesn't seem to be the StringSplit itself ). As far as I know, this can't be done, but maybe Val can correct me? About the 2D array: since you dim'ed the array 2D, you need to refer to it's elements by two dimensions too. So this will not work: Dim $wordArray[8][64] $wordArray[1] = "value" ... but this will work: So this will not work: Dim $wordArray[8][64] $wordArray[1][2] = "value" Now to put an array into another array element... As I said, I don't know a way to do that, but maybe Val does? Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
DW1 Posted July 18, 2007 Share Posted July 18, 2007 does an array use a special separator like the pipe "|" ? If so you would need your sub arrays to use a diff separator right? AutoIt3 Online Help Link to comment Share on other sites More sharing options...
ChrisL Posted July 18, 2007 Share Posted July 18, 2007 Poster seems to want to put an array into another array element (issue doesn't seem to be the StringSplit itself ). As far as I know, this can't be done, but maybe Val can correct me? Yes you can #include<array.au3> $string = "my|words|i|Want" $string2="Some|More|words" $aString = StringSplit($String,"|") $aString2 = StringSplit($String2,"|") Dim $storage[3] $storage[1] = $aString $Storage[2] = $aString2 For $i= 1 to Ubound($Storage) -1 _arrayDisplay($storage[$i]) Next [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
myt Posted July 18, 2007 Author Share Posted July 18, 2007 Yes you can #include<array.au3> $string = "my|words|i|Want" $string2="Some|More|words" $aString = StringSplit($String,"|") $aString2 = StringSplit($String2,"|") Dim $storage[3] $storage[1] = $aString $Storage[2] = $aString2 For $i= 1 to Ubound($Storage) -1 _arrayDisplay($storage[$i]) Next How would I get the number of element in $storage[1]? I don't think I could just do $storage[1][0], because $storage is declared as a 1D array... Link to comment Share on other sites More sharing options...
SadBunny Posted July 18, 2007 Share Posted July 18, 2007 Yes you canOk! I tested something very much like your code to validate my former post... I have no idea why my attempt to to the exact same thing failed... To bad I didn't save my test code, really wondering what I did wrong. :"> Then the only remaining problem seems the '2D arrays need to be referenced in 2D' thing Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
ChrisL Posted July 18, 2007 Share Posted July 18, 2007 How would I get the number of element in $storage[1]? I don't think I could just do $storage[1][0], because $storage is declared as a 1D array... I think like this #include<array.au3> $string = "my|words|i|Want" $string2="Some|More|words" $aString = StringSplit($String,"|") $aString2 = StringSplit($String2,"|") Dim $storage[3] $storage[1] = $aString $Storage[2] = $aString2 For $i= 1 to Ubound($Storage) -1 _arrayDisplay($storage[$i]) Next $iminterestedinthisarray=ReadArrayArray($storage[1]) Msgbox(0,"",$iminterestedinthisarray[1]);storage[1] array element 1 Func ReadArrayArray(ByRef $array) return $array Endfunc [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
mikehunt114 Posted July 18, 2007 Share Posted July 18, 2007 (edited) How would I get the number of element in $storage[1]? I don't think I could just do $storage[1][0], because $storage is declared as a 1D array... Ubound($storage[1]) will work, so long as it contains a return value from StringSplit (important because of the fact that it is of a single dimension). Edit: typo Edited July 18, 2007 by mikehunt114 IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
myt Posted July 18, 2007 Author Share Posted July 18, 2007 Ok, I've made a workaround: I have to declare it as a 1D array , and use another temporary array. Dim $wordArray[8] $wordArray[1] = StringSplit(...) $tmpArray = $wordArray[1] $wordCount = $tmpArray[0] I couldn't just do $wordArray[1][0] because it's now a 1D array Link to comment Share on other sites More sharing options...
SadBunny Posted July 18, 2007 Share Posted July 18, 2007 Ok, I've made a workaround: I have to declare it as a 1D array , and use another temporary array. Dim $wordArray[8] $wordArray[1] = StringSplit(...) $tmpArray = $wordArray[1] $wordCount = $tmpArray[0] I couldn't just do $wordArray[1][0] because it's now a 1D array You can do: $tmpArray = $wordArray[1][0] In this case, $tmpArray would contain the 1D array stored in the 2D $wordArray[1][0] Roses are FF0000, violets are 0000FF... All my base are belong to you. 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