Can someone give me an example of how to access one class
from another using the friend property?
thanks
Printable View
Can someone give me an example of how to access one class
from another using the friend property?
thanks
friend is not a property. friend is uesd to declare a routine/property that only allows a class to be called by another class in the same application. calling it is no different than calling a public routine
Is it application based, or project based?Quote:
Originally posted by Cander
friend is not a property. friend is uesd to declare a routine/property that only allows a class to be called by another class in the same application. calling it is no different than calling a public routine
Here is the problem. If you could please help me fix
I have two collection classes in my project, which are declared in the form as private
Private mobjClassA As clsClassA
Private mobjClassB As clsClassB
Now in the mobjClassA I first load the data. Then I need to go to mobjClassB and need to loop through the
mobjClassA. I can't get a hold of how to use the Friend keyword and make the clsClassA accessible in the clsClassB
This is how I'm trying to use them
'Form code
Option Explicit
Private mobjClassA As clsClassA
Private mobjClassB As clsClassB
'clsClassA
Option Explicit
Private mcolLottery As Collection
'clsClassB
Option Explicit
Private mcolClassB As Collection
Private mcolClassA As Collection
Friend Property Let PassCollection(ClassACollection As Collection)
Set mcolClassA = ClassACollection
End Property
Private Sub Class_Initialize()
Set mcolClassA = New Collection
Set mcolClassB = New Collection
End Sub
Now when I'm in clsClassB I do
For each objClassA in mcolClassA
Next
To explain this easiest, I should give you a few of the different scope keywords used in the same context:
[Private | Public | Friend] [Sub | Function | Property [Get |Let |Set |] | Event] name [(arglist)]
Private:
The procedure may only be used from within the same module.
Friend:
The procedure may only be used from within the same projects.
Public:
The procedure may be used from any module in any project (if used in another project, the other project must have a reference set to it.)
What is objClassA. I dont see this decalred anywhere.
That is one messed up collection object example :D
Hope that helps...VB Code:
'in clsDogs Option Explict Private mcolObjects As Collection Public Get Item(ByVal plngIndex As Long) As clsDog Set Item = mcolObjects.Item(plngIndex) End property Public Function AddDog(ByVal pstrName As String) As clsDog Dim objDog As clsDog Set objDog = New clsDog objDog.Name = pstrName mcolObjects.Add objDog Set AddDog = objDog Set objDog = Nothing End Function Private Sub Class_Initialize() Set mcolObjects = New Collection End Sub Private Sub Class_Terminate() Set mcolObjects = Nothing End Sub 'In class clsDog Option Explicit Private mstrName As String Public Property Let Name(ByVal pstrValue As String) mstrName = pstrValue End Property Public Property Get Name() As String Name = mstrName End Property
Woka
Apparently....Quote:
Originally posted by Cander
What is objClassA. I dont see this decalred anywhere.
...is clsClassA :DVB Code:
'clsClassA Option Explicit Private mcolLottery As Collection
Hehehehehe...Sorry.
Silly Woka