Component Creation

  • Thread starter Thread starter Roshawn Dawson
  • Start date Start date
R

Roshawn Dawson

Hi All,

I am creating a component library and I have a function that contains
optional parameters. Here's the skeleton code for the function:

Public Function SearchBook(ByVal page as String, Optional ByVal keyword
As String = Nothing, Optional ByVal categoryID As String = Nothing) As Book

' implementation code omitted

End Function

My gripe is with the optional parameters. Specifically, this function
can be used three ways:

1. use take the page and keyword params (omitting the catagoryID param)
2. use the page and categoryID params (omitting the keyword param)
3. use all three params.

Are there any penalties for ignoring only one of the optional
parameters? Must they both be used (because I don't feel like writing
overloaded functions)if one of them is used? Is the order in which
they're placed an issue?

Thanks,
Roshawn
 
Roshawn Dawson said:
My gripe is with the optional parameters. Specifically, this function
can be used three ways:

1. use take the page and keyword params (omitting the catagoryID param)
2. use the page and categoryID params (omitting the keyword param)
3. use all three params.

Are there any penalties for ignoring only one of the optional
parameters? Must they both be used (because I don't feel like writing
overloaded functions)if one of them is used? Is the order in which
they're placed an issue?

I don't have a link to point to, but my understanding was that even though
you give it optional parameters, the compiler treats it as if all of them are
required. For code that does not use one of the optional parameters, the
compiler will simply add the default value in for the missing parameter.

Is the order an issue? I would think you should try to put the most
common in front, (to making coding easier) but when all are strings,
what could it matter?

Passing in Page as a string seems odd, shouldn't that be a number?

LFS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top