Results 1 to 3 of 3

Thread: Passing classes into a function

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Location
    Klamath Falls, OR
    Posts
    71

    Passing classes into a function

    Lets say I've got a function, and i need it to do somthing to an instance of my class, and that is the parameter of the function. I'm trying to do somthing like this:
    The function gets the .name property from the instance of the class and shows it in a msgbox (not what my function really does, but this makes it a bit more simple)

    Function GetName (ClassInstance as string)
    msgbox ClassInstance.Name
    End Function

    So when I call it like this supposing that Player1 is an instance of my class, it doesnt work.

    Getname (Player1)

    How can i get around this?

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Instead of decalring the parameter as a string yo uneed to declare as the class. For instance if the class is called cPlayerInfo then the declare the function like this:
    VB Code:
    1. Function GetName (ClassInstance as cPlayerInfo) as string
    2.    GetName =ClassInstance.Name
    3. End Function

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Location
    Klamath Falls, OR
    Posts
    71
    Thanks, I figured it out just before I read this... heheh, dont know what i was thinking. Thanks anyways though.

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