1

I am trying to declare a static array inside Budget class:

private Static budgets(1 To MAX_BUDGETS_AMOUNT) As Budget

I want it in order to have a "ready for action" array of already instantiated objects of the same class.

Vba gives me this syntax error while highlighting "budgets" with blue:

Compile error: Expected: Sub or Function or Property

Is it allowed to have a static array inside VBA class? If yes then how should I implement it? Thanks.

1
  • Static keyword can be used with Sub, Function, Property Let/Get/Set and at procedure level to declare variables. So it is not possible to have static array in a class directly. For more info about static see this article. Commented Feb 22, 2015 at 12:09

2 Answers 2

1

Help is quite clear. Static must be declared at procedure level.

I think you just want a module level variable. Use the Class Initialise function to fill it.

If Max_Budget is a variable it won't work. If it's a Const it will. There is no maths or expression evaluation done when declaring variables.

Sign up to request clarification or add additional context in comments.

2 Comments

Will the static variable inside class method be alive and available to other methods in the same class?
No it won't. You don't need or want a static variable. You need a normal module level variable declared with DIM. While your class exists it won't lose it's data.
1

I use this for my VBA script:

 Const AVALUES = "1:10:5" 
Public A(2) As Integer 

Public Sub MyMacro() 
    Dim vntTemp As Variant 
    Dim intIndex As Integer 
    vntTemp = Split(AVALUES, ":") 

    For intIndex = 0 To 2 
        A(intIndex) = vntTemp(intIndex) 
    Next 

    Debug.Print A(0) 
    Debug.Print A(1) 
    Debug.Print A(2) 
End Sub 

1 Comment

Can you please explain how it relates to my question? You declare an array but my problem was to make a static array in a class module...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.