Can you declare a constant array in VBScript?
An array is the result of a function call (Array()
) in VBScript. Only literal values can be made Const
. So: No, you can't.
Why not just declare the array as public and then assign the array during the start of the script?
Public arrQuarters
arrQuarters = Array("Q1", "Q2", "Q3", "Q4")
For Each Quarter in arrQuarters
wscript.echo Quarter
Next
You could define a function to return the array you want to use as a constant. For example:
For Each q in AllQuarters
wscript.echo q
Next
wscript.echo "element 0 = " & AllQuarters()(0)
AllQuarters()(0) = "X1"
wscript.echo "element 0 still = " & AllQuarters()(0)
Function AllQuarters()
AllQuarters = Array("Q1","Q2","Q3","Q4")
End Function