-
Dec 1st, 2013, 05:11 PM
#1
[RESOLVED] Question about Class module
In a class module is there a sub such as when you make an instance of the class that it is called where you can pass arguments?
Like in Java, for example, I have a class called Square
When I make an instance of this class I do this:
Square sq = new Square(x1,y1,x2,y2)
How to do this in VB for same named class
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Dec 1st, 2013, 05:43 PM
#2
Re: Question about Class module
I'm not sure if VB6 supports arguments on the create line or not, I know VB.Net does but in Vb6 you may need to create a procedure in you class that accepts those arguments and call that to initialize the class after the New
You definitely can't dim it on the same line as you assign a value in VB6 though you can in Vb.Net
-
Dec 1st, 2013, 05:47 PM
#3
Re: Question about Class module
The initialize event which is called when a class is created does not support arguments.
-
Dec 1st, 2013, 05:51 PM
#4
Re: Question about Class module
VB6 doesn't support class construtor, you can only add initialize code under Class_Initialize which doesn't accept arguments.
-
Dec 1st, 2013, 05:51 PM
#5
Re: Question about Class module
I thought that may be the case, been a while since I created a class that needed this in VB6
So you need a class and in that class you need a public sub or function that accepts the arguments then you need to call that sub/function after you create the New instance of the class
Code:
Dim MyClass as clsSquare
MyClass=New clsSquare
MyClass.MySub(x1,y1,x2,y2)
Or Square could be a function in the class which may make more sense, hard to say with the info provided
-
Dec 1st, 2013, 06:07 PM
#6
Re: Question about Class module
Originally Posted by DataMiser
I thought that may be the case, been a while since I created a class that needed this in VB6
So you need a class and in that class you need a public sub or function that accepts the arguments then you need to call that sub/function after you create the New instance of the class
Code:
Dim MyClass as clsSquare
MyClass=New clsSquare
MyClass.MySub(x1,y1,x2,y2)
Or Square could be a function in the class which may make more sense, hard to say with the info provided
Can the name of the sub be the same as the class name?
Code:
Dim MyClass as clsSquare
MyClass=New clsSquare
MyClass.clsSquare(x1,y1,x2,y2)
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Dec 1st, 2013, 06:17 PM
#7
Re: Question about Class module
Originally Posted by jmsrickland
Can the name of the sub be the same as the class name?
Code:
Dim MyClass as clsSquare
MyClass=New clsSquare
MyClass.clsSquare(x1,y1,x2,y2)
I was doubt but after testing, i found it is accepted!!
-
Dec 1st, 2013, 07:13 PM
#8
Re: Question about Class module
OK, then that's how I will do it.
Thanks all.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
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
|