Results 1 to 4 of 4

Thread: [RESOLVED] How can i pass an object as a parameter?

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    9

    Resolved [RESOLVED] How can i pass an object as a parameter?

    Hi, thanks for taking the time to look at this code. It throws an error when i try to pass a Dog object as a parameter to the printName method, i can't figure out why, could someone plz let me know?

    here is the code

    VB Code:
    1. Function start()
    2.  
    3. Dim adog As Dog
    4. Set adog = New Dog
    5. adog.Name = "rover"
    6. MsgBox (adog.Name) 'works fine, prints "rover" in a msgbox
    7.  
    8. printName (adog) 'This line causes error - Object doesnt support this property or method (Error 438)
    9.  
    10. End Function
    11.  
    12. Sub printName(adog As Dog)
    13.     MsgBox (adog.Name)
    14. End Sub

    Im using this code for a macro in an Excel document

    Thanks again
    <>GT<>

  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713

    Re: How can i pass an object as a parameter?

    VB Code:
    1. 'BEHIND THISWORKBOOK
    2. Option Explicit
    3.  
    4. Private Function start()
    5.  
    6.     Dim adog As Dog
    7.     Set adog = New Dog
    8.     adog.Name = "rover"
    9.     MsgBox (adog.Name) 'works fine, prints "rover" in a msgbox
    10.    
    11.     printName adog
    12.  
    13. End Function
    14.  
    15. Private Function printName(ByVal bdog As Dog)
    16.     MsgBox (bdog.Name)
    17. End Function
    18.  
    19. Private Sub Workbook_Open()
    20.     start
    21. End Sub
    VB Code:
    1. 'IN CLASS - DOG
    2. Option Explicit
    3.  
    4. Private m_Name As String
    5.  
    6. Public Property Get Name() As String
    7.     Name = m_Name
    8. End Property
    9.  
    10. Public Property Let Name(ByVal vNewValue As String)
    11.     m_Name = vNewValue
    12. End Property
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    610

    Re: How can i pass an object as a parameter?

    RobDog,

    Are you saying that Class objects have to be passed by value?

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    9

    Re: How can i pass an object as a parameter?

    Most appreciated Rob

    I can now continue my work

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