variable argument list? 
Author Message
 variable argument list?

I've been searching and searching but can't find it anywhere:

"How do I create a procedure that can take a variable list of arguments"

Something like:

sub dumptext( byval strText, byval blnBold)
    ...code...
end sub

sub dumptext( byval strText)
    dumptext( strText, FALSE)
end sub

However, the above doesn't work, so how /is/ it done in VBScript?

Many thanks in advance,

Eli-Jean Leyssens



Fri, 23 Nov 2001 03:00:00 GMT  
 variable argument list?
In VBScript, you can't.  There isn't any support for the Optional keyword in
the procedure definition.  If there were, you would code something like:

Sub MySub(arg1, arg2, Optional arg3, arg4)

where arg3 and arg4 would be optional.

The best you can do in VBScript is use an array for optional arguments.  the
downside is that you lose IntelliSense in VID.

Sub MySub(arg1, arg2, optionarry)

where you call it like this:

MySub(var1, "value2", array(empty,"arg4))

Example:

mysub "case1",array(empty,"c")
mysub "case2",array()
mysub "case3",array("b")
wscript.quit
sub mysub(arg1, optionarray)
  if ubound(optionarray) = -1 then
      msgbox arg1 & " " & "no optional args"
  elseif ubound(optionarray) = 1 then
    if not isempty(optionarray(0)) then
      msgbox arg1 & " " & optionarray(0)
    end if
    if not isempty(optionarray(1)) then
      msgbox arg1 & " " & optionarray(1)
    end if
  elseif ubound(optionarray) = 0 then
    if not isempty(optionarray(0)) then
      msgbox arg1 & " " & optionarray(0)
    end if
  end if
end sub

--
Michael Harris


I've been searching and searching but can't find it anywhere:

"How do I create a procedure that can take a variable list of arguments"

Something like:

sub dumptext( byval strText, byval blnBold)
    ...code...
end sub

sub dumptext( byval strText)
    dumptext( strText, FALSE)
end sub

However, the above doesn't work, so how /is/ it done in VBScript?

Many thanks in advance,

Eli-Jean Leyssens



Fri, 23 Nov 2001 03:00:00 GMT  
 variable argument list?

Quote:
> In VBScript, you can't.  There isn't any support for the Optional keyword
in
> the procedure definition.  If there were, you would code something like:
<snip>
> The best you can do in VBScript is use an array for optional arguments.
the
> downside is that you lose IntelliSense in VID.

K, thanx for the info.  However, that still leaves me wondering how it is
that for
instance the Open method of a ADO RecordSet does have optional parameters.
Is it because those routines have been written in another language that
/does/
support optional parameters and that that functionality is just exported
through
COM?

Cheers and thanks once again,

Eli-Jean Leyssens



Fri, 23 Nov 2001 03:00:00 GMT  
 variable argument list?
ADO isn't written in VBScript ;-)

--
Michael Harris


Quote:
> In VBScript, you can't.  There isn't any support for the Optional keyword
in
> the procedure definition.  If there were, you would code something like:
<snip>
> The best you can do in VBScript is use an array for optional arguments.
the
> downside is that you lose IntelliSense in VID.

K, thanx for the info.  However, that still leaves me wondering how it is
that for
instance the Open method of a ADO RecordSet does have optional parameters.
Is it because those routines have been written in another language that
/does/
support optional parameters and that that functionality is just exported
through
COM?

Cheers and thanks once again,

Eli-Jean Leyssens



Fri, 23 Nov 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. passing variable argument list from web page to web service (is it possible)

2. variable size argument list in vbs?

3. function argument list...

4. Question on the Function Argument List

5. Unable to execute - arguments list is too long

6. argument list too long errors

7. Arguments list.

8. Unable to execute - arguments list is too long

9. unable to execute - arguments list is too long...

10. How to pass a variable as an argument

11. Can the arguments in BuildKeyCodes be variables?

12. variable number of arguments?

 

 
Powered by phpBB® Forum Software