burak Posted August 26, 2003 Posted August 26, 2003 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 Quote
*Experts* mutant Posted August 26, 2003 *Experts* Posted August 26, 2003 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. Quote
burak Posted August 26, 2003 Author Posted August 26, 2003 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 Quote
*Experts* mutant Posted August 26, 2003 *Experts* Posted August 26, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.