Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Assigning a default value to a function-variable

Reply
Thread Tools

Assigning a default value to a function-variable

 
 
0rsted
Guest
Posts: n/a
 
      06-25-2005
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...
 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      06-25-2005
0rsted wrote:
> 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

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VPN Client is assigning the same IP Address to both the interface andthe default gateway. dnash Cisco 0 01-02-2008 03:03 PM
VPN Client is assigning the same IP Address to both the interface andthe default gateway. dnash Cisco 0 01-02-2008 03:02 PM
assigning to hash keys when there is a default value? 7stud -- Ruby 35 09-07-2007 01:52 PM
Assigning methods to objects, and assigning onreadystatechange to an XMLHttpRequest -- an inconsistency? weston Javascript 1 09-22-2006 09:33 AM
Using default a empty dictionary as a default value C Gillespie Python 3 03-22-2005 12:22 PM



Advertisments