Reputation: 8659
Good Day,
I'm creating a VBScript function to return an array. But I want to pass in a parameter for the array size.
Function CreateArray(arraySize)
Dim someArray(arraySize) ' EXPECTED INTEGER CONSTANT
For i = 0 to UBound(someArray)
someArray(i) = 5
Next
CreateArray = someArray
End Function
But I'm getting an error:
Expected integer constant
Is this possible to do in VBScript?
TIA,
coson
Upvotes: 9
Views: 10128
Reputation: 13215
Yes. You use the Redim
statement:
Function CreateArray(arraySize)
Dim someArray()
Redim someArray(arraySize)
For i = 0 to UBound(someArray)
someArray(i) = 5
Next
CreateArray = someArray
End Function
Upvotes: 16