Wednesday, March 30, 2011

Can you declare a constant array in VBScript?

I want to use an array that I declare once at the top of my code several times. Ex.

Const Quarters = ["Q1", "Q2", "Q3", "Q4"]

For each Quarter q q.Do some work

Etc.

Can this be done in VBScript?

From stackoverflow
  • Simple answer: no. The array cannot be made const.

  • 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 myArray(3) 
    arrQuarters = Array("Q1", "Q2", "Q3", "Q4")
    
    For Each Quarter in arrQuarters
        wscript.echo Quarter
    Next
    

0 comments:

Post a Comment