VBScript creates an array in a function based on a parameter

Good afternoon,

I am creating a VBScript function to return an array. But I want to pass a parameter for the size of the array.

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 get an error message:

Expected Integer Constant

Can this be done in VBScript?

TIA

Coson

+6
source share
1 answer

Yes. You are using the Redim :

 Function CreateArray(arraySize) Dim someArray() Redim someArray(arraySize) For i = 0 to UBound(someArray) someArray(i) = 5 Next CreateArray = someArray End Function 
+11
source

Source: https://habr.com/ru/post/911370/


All Articles