Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP- Default values in Function Argument List

Status
Not open for further replies.

abraxas

Programmer
Jan 15, 2001
75
AU
Hi,
In some languages like PHP you can set a default Argument in a function such as

myFunction(myValue = 0) {
Return myValue
}

print myFunction()
Output >> 0
Is there an equivalent in ASP (not .net)?
I had a good look around but can't find what I'm after, I'm unsure what it is called.

abraxas
 
from an article on 4guysfromrolla.com

Question: How can I make an argument of a Function or Sub optional?
[Print this FAQ]

--------------------------------------------------------------------------------

Answer: In VBScript, the Optional keyword (which allows some arguments to be left out in VB) is not implemented. This means that you must declare every argument that you want to use. What you can do is pass null values to your functions:
Code:
<%
  Function SomeArgs(one, two, three, four)
    SomeArgs = one & two & three & four
  End Function

  Response.Write SomeArgs(1, 2, 3, null)
  ' The above statement writes 123 to the browser
%>



Bastien

Cat, the other other white meat
 
Thank you Bastien,
I decided to to work around the problem buy moving it to seperate class function. At least I know that it is called "optional"
Thanks
abraxas
 
also another recommendation i've seen and used is if you are sure to not pass things like objects or arrays, you can :


function whatever(ARGS) ... where ARGS is a string value comprised of delimited arguments like:

blah = whatever("1,2,dog,fire,chewtoy")

thus giving you the choice to split/chew whatever you want with the inbound argument into multiple args. and in turn gives the room to make virtual Optional arguments.

and lastly, the original question about a default value, can be processed like :

function whatever(arg1, arg1, arg3)
if arg1 = "" or isnull(arg1) then
arg1="cat"
end if
Etc...

thus forcing a precoded value for that argument in said instances.

hope the info helps

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
Hey Drexor,
Thanks a lot for the response but if I call function() with nothing you still get expected argument type error.

Just a subsidary question. I'm seriously considering re-coding an entire site in ASP.NET (support for Associative arrays-which is why I have this problem) but there are limiting factors, I don't own VS and it took one hour to write a "Hello World" ASP.Net (vb). Anywhere you can suggest I go to help degrease my learning curve on .NET?

Abraxas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top