|
-
Nov 27th, 2002, 12:38 PM
#1
Thread Starter
Hyperactive Member
Friend property
Can someone give me an example of how to access one class
from another using the friend property?
thanks
-
Nov 27th, 2002, 12:41 PM
#2
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
-
Nov 27th, 2002, 12:53 PM
#3
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
Is it application based, or project based?
-
Nov 27th, 2002, 12:55 PM
#4
Thread Starter
Hyperactive Member
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
-
Nov 27th, 2002, 12:55 PM
#5
Fanatic Member
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.)
-
Nov 27th, 2002, 01:07 PM
#6
What is objClassA. I dont see this decalred anywhere.
-
Nov 27th, 2002, 01:08 PM
#7
That is one messed up collection object example 
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
Hope that helps...
Woka
-
Nov 27th, 2002, 01:15 PM
#8
Originally posted by Cander
What is objClassA. I dont see this decalred anywhere.
Apparently....
VB Code:
'clsClassA
Option Explicit
Private mcolLottery As Collection
...is clsClassA 
Hehehehehe...Sorry.
Silly Woka
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
|