Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

 

In C/C++ you can have functions with default values.

 

From http://www.uq.net.au/~zzmiadam/tute/Basic/functions.htm

 

" char DefaultFunc( int A = 5 )

 

means that if the function is called without any parameters passed, the value for A defaults to 5, otherwise it takes on the value passed, so:

 

result = DefaultFunc(22) ; //A is assigned a value of 22

result = DefaultFunc() ; //value of A defaults to 5

 

"

 

Can you do the same in VB.NET?

 

I have a function that returns the next business day

 

"Function ReturnNextBusinessDay(ByVal inDate As Date) As Date"

 

I want the function declaration to be in such a way that inDate will have a blank default value. The function will use today's date if inDate is blank.

 

How can this be done?

 

Thank you,

 

Burak

  • *Experts*
Posted
You can use the Optional keyword, but this is only supported in VB.NET and not in any other language. The right way to do this is to make overloads.
Posted

Thanks,

 

I wrote a declaration like this

 

Function ReturnNextBusinessDay(Optional ByVal inDate

As Date = #1/1/1000#) As Date

 

I just check for 1/1/1000 in the function and use

today's date if function was called with no

parameters.

 

I would like to compile this function and make it

available to other pages in the project.

 

- What kind of file should I place this function in ?

 

ie.. .aspx, etc...

 

- How do I call this function from other pages? From

the code behind files especially.

 

Thanks,

 

Burak

  • *Experts*
Posted
If you want all pages to have access to it then put in a class in your project, and make the function shared if you dont want to create objects of the class.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...