Jump to content

Assigning array to array


 Share

Recommended Posts

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

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

Poster seems to want to put an array into another array element (issue doesn't seem to be the StringSplit itself :whistle:). 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... :lmao: 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

Poster seems to want to put an array into another array element (issue doesn't seem to be the StringSplit itself :whistle:). 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
Link to comment
Share on other sites

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

Yes you can

Ok! 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 :whistle:

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...