Hi all,
Can we pass arguments in the Class Intialise Event(Dll Creation) ?
Printable View
Hi all,
Can we pass arguments in the Class Intialise Event(Dll Creation) ?
Nope VB6 (and earlier versions) doesn't have any constructor method that can be overwritten. You'll have to create your own Init method that can be called directly after the object is created.
Any simple Example ?
In your class module simply add a public Sub or Function like this:You'll then have to call the Init method:Code:Public Sub Init(ByVal arg1 As Long, ByVal arg2 As String)
'do whatever
End Sub
Code:Dim obj As MyClassName
Set obj = New MyClassName
Call obj.Init(27, "Some string")
Congratulations on 10K Joacim! :thumb:
As mentioned, you can't pass arguments to the Initialize event, but another possibility to create your own public method and pass it parameters.
Example:Code:Set myObj = New Class1
Call myObj(Parameter)
Hack - double check your coding there.... That should generate a syntax error....
Might find this works better:
-tgCode:Call myObj.InitThis(Parameter)
the VBCorlib library uses the technique of creating a method named NewClassName which returns the new instance..
I've adopted this into my own projects.Code:Dim o As MyClass: Set o = NewMyClass(10, 22)
Public Function NewMyClass(ByVal X As Integer, ByVal Y As Integer)
Set NewMyClass = new MyClass
MyClass.X = X
MyClass.Y = Y
End Function