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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With