Array - VBScript


The Array() command in VB Script allows you to create an array, a data structure that can store a collection of values of the same type. It’s commonly used for storing and manipulating data in a structured manner.


Array([String1, String2, ...])
  • Values: One or more comma-separated literal values to initialize the array.




Example 1: Creating an array with literal values

Dim myArray = Array("Item 1", "Item 2", "Item 3")

Example 2: Accessing array elements

Dim myArray
myArray = Array("A", "B", "C")
Debug.Print myArray(0)  ' Outputs: "A"

Common Issues

  • Adding Elements after Creation: Arrays are fixed in size upon creation. Adding or removing elements dynamically is not supported.
  • Type Mismatch: All values in an array must be of the same type. Mixing types can cause runtime errors.


  • Looping Through Arrays: Use For Each loops to iterate over array elements.
  • Passing Arrays as Arguments: Pass arrays as arguments to functions and procedures for processing.
  • Collection: Represents a dynamic array-like collection that allows adding and removing elements.
  • Scripting.FileSystemObject: Provides methods for working with file systems, including creating and manipulating arrays of files and folders.