VBScript Basics, Part 61 | Join Multidimensional Array (Arrays)


Visual Basic Script (.vbs) Basic Tutorial:
Learn how to join a multidimensional array, display it in a grid like fashion, and also convert it to a single one dimensional array.

CODE EXAMPLE:

Dim multD(3,2)

multD(0,0) = “First:”
multD(0,1) = “Last:”
multD(0,2) = “Age:”

multD(1,0) = “Jeremy”
multD(1,1) = “England”
multD(1,2) = “49”

multD(2,0) = “Max”
multD(2,1) = “Schnitzl”
multD(2,2) = “23”

multD(3,0) = “Samuel”
multD(3,1) = “Lang”
multD(3,2) = “14”

‘Join
Function mJoin(list, delimiter)
For Each item In list
allItems = allItems & item & delimiter
Next
mJoin = allItems
End Function

‘Join for displaying
Function mDJoin(list)

For r = 0 To UBound(list,1) : For c = 0 To UBound(list,2)
If c = 0 And Not r = 0 Then
allItems = allItems & vbLf
End If
allItems = allItems & list(r,c) & vbTab
Next : Next

mDJoin = allItems
End Function