Is it possible to declare a public variable in vba and assign a default value?

后端 未结 8 699
旧时难觅i
旧时难觅i 2020-12-09 01:33

I want to do this but it won\'t compile:

Public MyVariable as Integer = 123

What\'s the best way of achieving this?

8条回答
  •  感动是毒
    2020-12-09 01:54

    Sure you know, but if its a constant then const MyVariable as Integer = 123 otherwise your out of luck; the variable must be assigned an initial value elsewhere.

    You could:

    public property get myIntegerThing() as integer
        myIntegerThing= 123
    end property
    

    In a Class module then globally create it;

    public cMyStuff as new MyStuffClass
    

    So cMyStuff.myIntegerThing is available immediately.

提交回复
热议问题