Assigning a default value to a function-variable

0

0rsted

Well, it's quite simple, it's easily done in C, but in ASP (and VB in
general) i haven't been able to see it done...

function setvalues(var1, var2="a", var3="b")
if var2="a" then
response.write("Var2 wasn't defined")
end if
if var3="b" then
response.write("Var3 wasn't defined")
end if
end function

I hope it makes sense, and that someone has the solution to it...
 
B

Bob Barrows [MVP]

0rsted said:
Well, it's quite simple, it's easily done in C, but in ASP (and VB in
general) i haven't been able to see it done...

function setvalues(var1, var2="a", var3="b")
if var2="a" then
response.write("Var2 wasn't defined")
end if
if var3="b" then
response.write("Var3 wasn't defined")
end if
end function

I hope it makes sense, and that someone has the solution to it...

That's because it's not possible to assign default values for parameters in
the method declaration statements in vb/vbscript.

In VB, you can declare parameters using the Optional keyword, and use the
IsMissing method to test whether or not the arguments were supplied. This is
not the case in vbscript. Of course, given the fact that all variables are
Variant in vbscript, it's not something that can't be worked around:

<%
function setvalues(var1,var2,var3)
if len(var2)=0 then
response.write("Var2 wasn't defined")
end if
if len(var3)=0 then
response.write("Var3 wasn't defined")
end if
end function

setvalue 6
%>

Bob Barrows
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top