Multidimensional, multidimensional arrays 
Author Message
 Multidimensional, multidimensional arrays

Imagine two, two-dimensional arrays, one placed into an element of the
other for easy hierarchical looping:

*CATEGORIES*                  | *ITEMS*
*What          *placeholder   | *what                  *color
Shirts         {empty}        | Button-Down Oxford     Blue
                              | Polo                   Red
                              | Henley                 Gray

dim CatArray, ItemArray
redim CatArray(1, 0)
redim ItemArray(1, 2)
'--- somewhere in here all the values get assigned
ItemArray(0,0) = "Button-Down Oxford"
ItemArray(1,0) = "Blue"
'--- and so on...
CatArray(1,0) = ItemArray
var = CatArray(1,0)(1,1)

"var" now equals "red".  In Visual Basic and VBScript, no problems.
Now, if I want to do this more than once, as in

*CATEGORIES*                  | *ITEMS*
*What          *placeholder   | *what                  *color
Shirts         {blank}        | Button-Down Oxford     Blue
                              | Polo                   Red
                              | Henley                 Gray
Pants          {empty}        | Corduroy               Black
                              | Twill                  OD Green
                              | Brushed Denim          Indigo

I do this:

redim CatArray(1, 0)
redim ItemArray(1, 2)
'--- assign the first set of values
ItemArray(0,0) = "Button-Down Oxford"
'--- etc, etc, etc
CatArray(1,0) = ItemArray
'--- reset the item array for the next set of values
itemArray = ""
redim ItemArray(1, 2)
'--- assign the second set of values
ItemArray(0,0) = "Corduroy"
'--- etc, etc, etc
CatArray(1,1) = ItemArray

var = CatArray(1,1)(1,1)

In Visual Basic, "var" now equals "OD Green".  In VBScript however,
the same code returns a "Type mismatch" error.  Is there something I'm
overlooking, or is what I'm attempting not possible in VBScript?

Thanks!

Bill Morris
Seritas L.L.C.



Mon, 07 Feb 2005 04:41:40 GMT  
 Multidimensional, multidimensional arrays
try redim preserv

Quote:
>-----Original Message-----
>Imagine two, two-dimensional arrays, one placed into an
element of the
>other for easy hierarchical looping:

>*CATEGORIES*                  | *ITEMS*
>*What          *placeholder   | *what                  
*color
>Shirts         {empty}        | Button-Down Oxford    
Blue
>                              | Polo                   Red
>                              | Henley                
Gray

>dim CatArray, ItemArray
>redim CatArray(1, 0)
>redim ItemArray(1, 2)
>'--- somewhere in here all the values get assigned
>ItemArray(0,0) = "Button-Down Oxford"
>ItemArray(1,0) = "Blue"
>'--- and so on...
>CatArray(1,0) = ItemArray
>var = CatArray(1,0)(1,1)

>"var" now equals "red".  In Visual Basic and VBScript, no
problems.
>Now, if I want to do this more than once, as in

>*CATEGORIES*                  | *ITEMS*
>*What          *placeholder   | *what                  
*color
>Shirts         {blank}        | Button-Down Oxford    
Blue
>                              | Polo                   Red
>                              | Henley                
Gray
>Pants          {empty}        | Corduroy              
Black
>                              | Twill                  OD
Green
>                              | Brushed Denim          
Indigo

>I do this:

>redim CatArray(1, 0)
>redim ItemArray(1, 2)
>'--- assign the first set of values
>ItemArray(0,0) = "Button-Down Oxford"
>'--- etc, etc, etc
>CatArray(1,0) = ItemArray
>'--- reset the item array for the next set of values
>itemArray = ""
>redim ItemArray(1, 2)
>'--- assign the second set of values
>ItemArray(0,0) = "Corduroy"
>'--- etc, etc, etc
>CatArray(1,1) = ItemArray

>var = CatArray(1,1)(1,1)

>In Visual Basic, "var" now equals "OD Green".  In
VBScript however,
>the same code returns a "Type mismatch" error.  Is there
something I'm
>overlooking, or is what I'm attempting not possible in
VBScript?

>Thanks!

>Bill Morris
>Seritas L.L.C.
>.



Mon, 07 Feb 2005 07:21:27 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Change Array to Multidimensional Array

2. Grab first column in multidimensional array

3. NEWBIE QUESTION: ReDim Preserver Multidimensional Arrays ??

4. multidimensional arrays?

5. multidimensional arrays/length ?

6. dynamic multidimensional array?

7. Multidimensional Array Sorting

8. problem assigning multidimensional array...

9. sorting a multidimensional array by value, descending

10. Multidimensional arrays

11. Multidimensional arrays

12. Help with multidimensional array -- hard way

 

 
Powered by phpBB® Forum Software