For example, to create a string array of 5 elements (0 to 4):
Dim MyArray as System.Array
MyArray = System.Array.CreateInstance(GetType(String),5))
which is equivalent to the following code at compile time:
Dim MyArray(4) as String
The same technique can be used to dynamically create arrays of any type at runtime.
Note that the above example assumes Option Strict is off. If Option Strict is on, you must use the .SetValue and .GetValue methods to access the array elements. If Option Strict is on, a proper code sample would be:
'Option Strict On
Dim mya As System.Array
mya = System.Array.CreateInstance(GetType(String), 3)
MessageBox.Show("Element (2) is " & _
Convert.ToString(mya.GetValue(2))) 'Returns "Word3"
Hope that helps.