The following is an example class in a class module
Private mKey As String
Private mValue As String
'CREATE INSTANCE
Public Static Function CreateInstance(Key As String, Value As String) As ExampleClass
Dim obj As New ExampleClass
obj.InitialiseKey (Key)
obj.InitialiseValue (Value)
Set CreateInstance = obj
End Function
'INITIALISE
Public Sub InitialiseKey(Key As String)
mKey = Key
End Sub
Public Sub InitialiseValue(Value As String)
mValue = Value
End Sub
Public Sub InitialiseKVP(Key As String, Value As String)
mKey = Key
mValue = Value
End Sub
'GETTER
Public Property Get Value() As String
Value = mValue
End Property
Public Property Get Key() As String
Key = mKey
End Property
And the following code is in a regular module
Sub Example_1()
Dim A As New ExampleClass
A.InitialiseKey ("Key 1")
A.InitialiseValue ("Value 1")
Debug.Print A.Key
Debug.Print A.Value
End Sub
Sub Example_2()
Dim A As New ExampleClass
'A.InitialiseKVP ("Key 2", "Value 2") 'DOES NOT COMPILE, EXPECTS '=' FOR SOME REASON
Debug.Print A.Key
Debug.Print A.Value
End Sub
Sub Example_3()
Dim A As ExampleClass
Set A = ExampleClass.CreateInstance("Key 3", "Value 3") 'RUNTIME ERROR 424, no object
Debug.Print A.Key
Debug.Print A.Value
End Sub
'Example_1' works, 'Example_3' is what i want to write. 'Example_2' was meant to be intermediate but does not even compile.
There is an answer on stackoverflow (Class (Static) Methods in VBA) essentially stating that methods can not be called. This seems odd to me since 'Example_1' calls a method and 'Example_3' compiles without error.
How do i get 'Example_2' to compile? How do i get 'Example_3' to work?