Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 4th, 2007, 09:44 AM
Registered User
Points: 1,897, Level: 17
Points: 1,897, Level: 17 Points: 1,897, Level: 17 Points: 1,897, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Mumbai, Maharastra, India.
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default how do i set default parameter value..

in ASP function.
e.g.
function test(x,y)
test = x+y
end function
------------
test(3)
since y is not given it should be consider as 0...but how...any idea??

Rupen Anjaria.:)
------------------
We CAN'T avoid problems, but can solve it.
 
Old January 4th, 2007, 02:40 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As far as I know, VBScript does not allow optional parameters.
There are a couple of cludgy work arounds, such as passing an array, but they really aren't useful imo.

Woody Z
http://www.learntoprogramnow.com
 
Old January 4th, 2007, 04:17 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

IMHO optional parameters are a poor way of doing things.

For example, in VB.NET I can write a method or function like this:

Public Sub foo(ByVal s as string, Optional ByVal b as Boolean = False)
//do something
End Sub

When this gets compiled by the Runtime the code will have an operator like this: [opt] denoting that the parameter is optional but in C# (or Java, JavaScript etc etc etc) there is no Optional Keyword and nor should there be as it defeats the purpose of overloading.

So, Rupen, using your example I would do something like this:

Public Function test(ByVal x as Integer) as Integer
Return x
End Function

Public Function test(ByVal x as Integer, ByVal y as Integer) as Integer
Return (x + y)
End Function

I know that this is a Classic ASP question so you will have to forgive the .NET code but Programming Theory is Programming Theory regardless of the language.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old January 4th, 2007, 08:01 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by dparsons
 IMHO optional parameters are a poor way of doing things.

For example, in VB.NET I can write a method or function like this:

Public Sub foo(ByVal s as string, Optional ByVal b as Boolean = False)
//do something
End Sub

When this gets compiled by the Runtime the code will have an operator like this: [opt] denoting that the parameter is optional but in C# (or Java, JavaScript etc etc etc) there is no Optional Keyword and nor should there be as it defeats the purpose of overloading.

So, Rupen, using your example I would do something like this:

Public Function test(ByVal x as Integer) as Integer
Return x
End Function

Public Function test(ByVal x as Integer, ByVal y as Integer) as Integer
Return (x + y)
End Function

I know that this is a Classic ASP question so you will have to forgive the .NET code but Programming Theory is Programming Theory regardless of the language.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
Unfortunately, you can't do this in Classic ASP. You can't overload methods, regardless of the signature.

Woody Z
http://www.learntoprogramnow.com
 
Old January 4th, 2007, 11:12 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I wasn't implying you could (although i did not know you couldnt overload in Classic) just stating some theory.



-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old January 5th, 2007, 12:14 AM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by dparsons
 I wasn't implying you could (although i did not know you couldnt overload in Classic) just stating some theory.
Sorry about that - I just wanted to make sure it was clear that overloading isn't available in VBScript (or VB6 for that matter), even though it would be nice. Of course, in VB6 you can have optional parameters, which works quite nicely, but as you stated it is pretty limited compared to overloaded methods. Also, VB6 offers the paramarray - which is great for cases where you must handle an unknown number of parameters. Again - VBScript doesn't provide this.

Woody Z
http://www.learntoprogramnow.com




Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 6 error: Parameter.. .has no default value ikaminow BOOK: Beginning VB.NET Databases 1 July 27th, 2007 07:39 AM
select all by default for parameter roy_mm Reporting Services 1 March 30th, 2007 03:48 PM
Change default date parameter format JeffHickman Reporting Services 0 February 14th, 2006 06:52 AM
Add default value to a parameter in a query marcin2k Access VBA 2 February 18th, 2005 04:39 PM
how to set parameter default value oranginalab Classic ASP Basics 0 August 28th, 2003 02:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.