|
-
Mar 26th, 2007, 05:26 PM
#1
Thread Starter
PowerPoster
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...
-
Mar 26th, 2007, 05:39 PM
#2
Re: Can't pass a Structure to a Sub Procedure???
 Originally Posted by blakemckenna
...I was using "Structure" as an illustration! ...
Shouldve said so in the first place
-
Mar 26th, 2007, 05:49 PM
#3
Re: Can't pass a Structure to a Sub Procedure???
 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.
-
Mar 26th, 2007, 05:55 PM
#4
Thread Starter
PowerPoster
Re: Can't pass a Structure to a Sub Procedure???
They don't make is easy do they?
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
|