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

--
LVL 1
MaugrisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MaxOvrdrv2Commented:
Dim aTest(3,3)

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

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


0
MaugrisAuthor Commented:

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
0
MaxOvrdrv2Commented:
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))

...........
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

MaxOvrdrv2Commented:
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.
0
MaugrisAuthor Commented:
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
0
MaxOvrdrv2Commented:
that is correct... which is also why there is no way of easily declaring the content of aTest(n,m), because of just that, it could be any number of elements by any number of elements... 1,1, to 1mill,1mill... so in order to declare the array, you must use integer constants. Once it's defined and declared, then you can populate it, by explicitly referencing the cursor position. Or else how will it know which element goes where within the X-Y (in our case) matrix? which is why you have to declare them 1 by 1...

in aTest2, an array of arrays, each element of the containing array is declared in it's definition... therefore, aTest2 is really a single array... so there is no cursor position problems with that one, since its cursor has one dimension, and goes from 0, to its length of elements (array(x),array(x) would have a length of 1... 0 and 1... ).

The main reason why you can't simply abstract declare the other array (0,0), is because the system cannot know, inherently, how many 2nd D elements are contained within each 1st D elements... in essence, whenever you declared something like this let's say:

aTest(,)

the system would have to reserver an infinite amount of memory as soon as it saw that it was a multidimensional array to compensate for the unknown amount of elements... because the comma, could also, in essence, be the definition of elements in an array, which constitutes the first element of the multiD array... get it? it could go on like this forever...

so declaring using integer constants, and referencing each cursor position explicitely when populating, remedies to that... so in the example above (prev. paragraph), it would look like this:

aTest(1,1)

aTest(0,0)=Array(Array("1","2"), Array("3","4"))
aTest(0,1)=Array(Array("5","6"), Array("7","8"))

and so forth, but never ever passed the integer constant length of 1 X 1 elements... no matter what those elements are...

i don't know if this makes any sense to you... sometimes i can bable a lot! lol! but this is essentially WHY you have to declare it explicitely like that...

if you were to try and declare this instead:

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

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

hope this explains a bit better...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MaxOvrdrv2Commented:
**** 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))


************************
0
MaxOvrdrv2Commented:
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.
0
MaugrisAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.