Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code Re-use in user-defined classes? 1

Status
Not open for further replies.

Brando32

Programmer
Jul 25, 2002
11
US
When you create a VB 6 class and then create many instantiations of this class during run-time - is the code part of the class shared among all the instantiations or is it re-created seperately each time?

(I ask because I am debating whether to use this class as a base data type for say, a linked-list or an array (which may have many elements) and wanted to know how to approach it.)
 
The code part is shared amongst all instances. The per-instance data is only used by the uhhhh instance.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thanks Chiph!! That makes my design decision easy ... I keep doing the object oriented way!
 
Isn't that one of the things that is supposed to make OOP so wonderful?


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Yes. :)
I just didn't know if VB 6 could muster it - I mean it's not fully oop, right?
 
What about if one of the functions declares a static var?
 
Statics are special cases -- they're sortof like global variables.

I try and not use them if I can. From a code maintenance perspective, they're on the fringe of the VB6 language, and you're not assured that a maintenance programmer will know all their ins & outs.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
The static variable will not carry over from instance to instance.



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
To test start a new project and add a class module and a command button with the following code.


'form module
Private Sub Command1_Click()
Dim MyClass1 As New Class1
Dim MyClass2 As New Class1

MyClass1.test "String 1"
MyClass1.test "String 2"
MyClass1.test "String 3"

MyClass2.test "String 4"
MyClass2.test "String 5"
End Sub

'add to class module

Public Function StaticTest(strValue As String) As String
Static strOut As String
strOut = strOut & strValue
MsgBox strOut
End Function



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top