Results 1 to 8 of 8

Thread: Can't pass a Structure to a Sub Procedure???

Hybrid View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Can't pass a Structure to a Sub Procedure???

    I was using "Structure" as an illustration!

    JMC...I have several Structures defined but I want to create a Generic Sub that will accept all the defined structures...
    Blake

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Can't pass a Structure to a Sub Procedure???

    Quote Originally Posted by blakemckenna
    ...I was using "Structure" as an illustration! ...
    Shouldve said so in the first place
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Can't pass a Structure to a Sub Procedure???

    Quote Originally Posted by blakemckenna
    I was using "Structure" as an illustration!

    JMC...I have several Structures defined but I want to create a Generic Sub that will accept all the defined structures...
    You can do as I have already suggested and declare the argument as type ValueType, but then the argument will accept any value type. I don't really see how that benefits you though. These types cannot have common functionality because they cannot inherit a common type (other than ValueType). What do you get by providing a single method for all types?

    You could also overload your method, providing one signature for each type. That is probably a more reasonable path because then you can call the same method regardless of the type and the system will choose the correct overload. Because each overload is specific to a type you can provide specific functionality. If you had a single method signature you'd only have to test types and cast within anyway, which doesn't make any sense.

    A further option is to declare an Interface and have all your structures implement it. Then you can declare your argument as that Interface type. That would also be a more sensible option if your structures actually do have common functionality.

    Finally, you could declare your types as classes instead of structures and have them all inherit a common base class.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Can't pass a Structure to a Sub Procedure???

    They don't make is easy do they?
    Blake

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