Resolved How to accept different sets of parameters in a function

WebKill2k

Member
Joined
May 15, 2008
Messages
14
Programming Experience
1-3
Is it possible to create a function that can be used passing it a couple of parameters, or something different instead, without writing it twice?

For instance, if I had a function that needed and X and Y value, could I create a function that could either accept two integers or a point variable?

Basically doing the following without writing it twice, hoping for something cleaner.


Public Function MyLocation(ByVal X as Integer, ByVal Y as Integer)
Do Stuff
Return Stuff
End Sub

Public Function MyLocation(ByVal here as Point)
Do Stuff
Return Stuff
End Sub
 
Last edited:
You need to write the different member definitions, but if they both perform the same work you only need to write that code once.

Although you can use arrays as parameters, and even make them ParamArray, I don't recommend that if parameters is not same types and for example only has Object type in common. I would not do that with your example, it is something that makes more sense with actual collection parameters.

There is also Optional parameters, but that makes sense to use when only some of them can be optional, and not to change the whole parameter list with interchanging parameters, it would make it difficult to use.
 
Back
Top