Link to home
Start Free TrialLog in
Avatar of Maugris
Maugris

asked on

Multidimensional arrays in vbScript

In vbScript if I do the following:
aTest = Array(Array(0,1),Array(0,1))
I access the elements as:
aTest(0)(0) etc.

Is there a way to format a single assignment statement so that I can access the elements as:
aTest(0,0) etc
Yes, I know that I can ReDim a dynamic array and assign whatever I want to the individual elements.  I'm hoping to find a way to fill a 2-D array in one statement.

Thx,
--MB

--
Avatar of MaxOvrdrv2
MaxOvrdrv2

Dim aTest(3,3)

access as:
aTest(0,0)
aTest(0,1)
aTest(0,2)

aTest(1,0)
aTest(1,1)
aTest(1,2)


Avatar of Maugris

ASKER


The response given is not a single assignment statement that populates a multidimensional array.

I've concluded that there is no answer to this problem.

I'll leave the question open for 7 days to see if perhaps I'm wrong.
--MB
here's a single line... didn't know that's exactly what you wanted... but this IS a multidimensional array... which can contain more than 2 dimensions, but here's how to populate the content directly, on one line, super easy ans straight forward:

dim aTest
aTest=Array(Array("some text", 17, 6, "", "some text", "some text", "", ""), Array("some more text", 4, 7, "x", "some more text", "some more text", "x", "x"))

referenced as:
response.write(aTest(0)(0))

...........
so to answer your original question, NO, the way you're using it now is the only way to truly declare a multi-dimensional array...

the other way (0,0), is not a true multi-dimensional array, so you have to assign the elements/text as i have given you above... so the answer is: no, there is no one liner to declare those kinds of arrays... but i've given you other methods of filling them.
Avatar of Maugris

ASKER

Hmmm,
Perhaps it is a matter of nomenclature, however, as I have always understood things,
aTest1(n,m) is an element of the 2-dimensional array aTest1
aTest2(n)(m)  is the mth element of an array which is itself the nth element of an array.
aTest2 is an array of arrays, not a multidimensional array.

In vBScript, there is nothing to constrain the data types of array elements -- all are variants
ASKER CERTIFIED SOLUTION
Avatar of MaxOvrdrv2
MaxOvrdrv2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
**** ADDITION, IT SHOULD READ ******

then the final result would be something like this: aTest1((0,0(8)),(0,0(8)))

a bit hard for the computer to understand this concept... our brains are still much better than computers, since we can do this in our heads very easily... computers are not like us, they need to be told everything, or else they use up every bit of memory they have and die ;)

OUR brains know that that the above really looks like this:

aTest1((8),(8))


************************
you would think that the simple, yet maybe not the wanted answer of: it cannot be done. which is correct, would merit some points?

UNLESS, he has found a solution on his own, in which case i would like to know what it is?

thank you and sorry for the objection but a "it cannot be done" is a valid solution.
Avatar of Maugris

ASKER

I have no objection to giving the guy points for his efforts.
I do, however object to giving him the points for his answer.

The first comment seems to indicate that the question was either misread or misunderstood.

By that time I had *already* posted the "it cannot be done" message based on my own research.
*AFTER* I had posted that the commenter posted several times, but the subsequent posts all seem to discuss arrays of arrays, which was not even the subject of the original question.

The comment that his answer "develops the "it can't be done" solution in a better way "  doesn't hold since it has no bearing on the original question.

Cheers,
--MB