Results 1 to 8 of 8

Thread: Friend property

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    320

    Friend property

    Can someone give me an example of how to access one class
    from another using the friend property?
    thanks

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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?
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    320
    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

  5. #5
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    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.)

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    What is objClassA. I dont see this decalred anywhere.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    That is one messed up collection object example
    VB Code:
    1. 'in clsDogs
    2. Option Explict
    3.  
    4. Private mcolObjects As Collection
    5.  
    6. Public Get Item(ByVal plngIndex As Long) As clsDog
    7.    Set Item = mcolObjects.Item(plngIndex)
    8. End property
    9.  
    10. Public Function AddDog(ByVal pstrName As String) As clsDog
    11. Dim objDog As clsDog
    12.    Set objDog = New clsDog
    13.    objDog.Name = pstrName
    14.    mcolObjects.Add objDog
    15.    Set AddDog = objDog
    16.    Set objDog = Nothing
    17. End Function
    18.  
    19. Private Sub Class_Initialize()
    20.    Set mcolObjects = New Collection
    21. End Sub
    22.  
    23. Private Sub Class_Terminate()
    24.    Set mcolObjects = Nothing
    25. End Sub
    26.  
    27.  
    28. 'In class clsDog
    29. Option Explicit
    30.  
    31. Private mstrName   As String
    32.  
    33. Public Property Let Name(ByVal pstrValue As String)
    34.    mstrName = pstrValue
    35. End Property
    36.  
    37. Public Property Get Name() As String
    38.    Name = mstrName
    39. End Property
    Hope that helps...

    Woka

  8. #8
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Originally posted by Cander
    What is objClassA. I dont see this decalred anywhere.
    Apparently....
    VB Code:
    1. 'clsClassA
    2.  
    3. Option Explicit
    4.  
    5. 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
  •  



Click Here to Expand Forum to Full Width