|
-
Dec 5th, 2007, 05:15 AM
#1
Parameters in Class
Hi all,
Can we pass arguments in the Class Intialise Event(Dll Creation) ?
Please mark you thread resolved using the Thread Tools as shown
-
Dec 5th, 2007, 05:19 AM
#2
Re: Parameters in Class
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.
-
Dec 5th, 2007, 05:58 AM
#3
Please mark you thread resolved using the Thread Tools as shown
-
Dec 5th, 2007, 08:27 AM
#4
Re: Parameters in Class
In your class module simply add a public Sub or Function like this:
Code:
Public Sub Init(ByVal arg1 As Long, ByVal arg2 As String)
'do whatever
End Sub
You'll then have to call the Init method:
Code:
Dim obj As MyClassName
Set obj = New MyClassName
Call obj.Init(27, "Some string")
-
Dec 5th, 2007, 11:47 AM
#5
Re: Parameters in Class
Congratulations on 10K Joacim! 
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)
-
Dec 5th, 2007, 12:42 PM
#6
Re: Parameters in Class
Hack - double check your coding there.... That should generate a syntax error....
Might find this works better:
Code:
Call myObj.InitThis(Parameter)
-tg
-
Dec 5th, 2007, 04:59 PM
#7
New Member
Re: Parameters in Class
the VBCorlib library uses the technique of creating a method named NewClassName which returns the new instance..
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
I've adopted this into my own projects.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|