Is there a way to overload the constructor / initialize procedure for a class in VBA?

前端 未结 4 885
时光取名叫无心
时光取名叫无心 2020-12-11 04:37

In C#, I know that I can overload the constructor for a class by specifying it in the body of the class:

public class MyClass()
{
    public MyClass(String s         


        
4条回答
  •  失恋的感觉
    2020-12-11 05:30

    No, classes cannot be initialized with parameters in VBA. This wouldn't be legal because of the Dim ... As New ... statement, which implicitly constructs objects when they're first accessed.

    Dim x As New MyClass
    
    x.Prop = 42 ' Before x.Prop is set, x is implicitly constructed
    

提交回复
热议问题