1

I need to create multi-dimensional array of strings. Each row of the array can have varying number of strings. Something like the follwing code:

twoDimension = Array(Array())  
ReDim Preserve twoDimension(3)  
For i = 0 to 2  
 If i = 1 Then  
  twoDimension(i) = Array(1,2,3)  
 End If  
 If i = 2Then  
     twoDimension(i) = Array(1,2,3,4,5)  
   End If  
Next  

2 Answers 2

2

How about a dictionary

Set a = CreateObject("Scripting.Dictionary")
a.Add 0, Array(1,2,3)
a.Add 1, Array(4,5,6)
MsgBox a.Count
MsgBox a.Item(0)(2)
MsgBox a.Item(1)(1)
Sign up to request clarification or add additional context in comments.

Comments

0

There's nothing wrong with having jagged arrays in VBScript. There are some minor issues with your code (ReDim to 3 but only assigning values to 2, unnecessarily using a For loop to assign values), but in general, that's the correct syntax to use.

Option Explicit

Dim twoDimension, i, j

twoDimension = Array(Array())  
ReDim Preserve twoDimension(2)

twoDimension(1) = Array(1,2,3)
twoDimension(2) = Array(1,2,3,4,5)

For i = 0 To UBound(twoDimension)
  For j = 0 To UBound(twoDimension(i))
    WScript.Echo "(" & i & "," & j & ") = " & twoDimension(i)(j)
  Next
Next

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.