Optional Parameters 
Author Message
 Optional Parameters

I am sure this is as basic as it gets, however can you please let me know
how to declare a Sub() which includes optional parameters eg:

Sub MyRoutine(param1, param2, param3)

End Sub

Where param 3 has a default value lets say ("") an empty string...

All help appreciated

Thanks in advance

Ian James



Sun, 11 May 2003 03:00:00 GMT  
 Optional Parameters

Quote:

> I am sure this is as basic as it gets, however can you please let me
> know how to declare a Sub() which includes optional parameters eg:

> Sub MyRoutine(param1, param2, param3)

> End Sub

> Where param 3 has a default value lets say ("") an empty string...

> All help appreciated

> Thanks in advance

> Ian James


Scripting does NOT support this.  One common work around is to use a
single array as the argument and then to have logic in the subroutine to
parse out the proper arguments.  The other is to concatenate the
arguments into a string with a delimiter and then use Split to parse off
the supplied arguments.  I posted a response recently that has an
example, if you care to search for it.

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/



Sun, 11 May 2003 03:00:00 GMT  
 Optional Parameters


Quote:

> > I am sure this is as basic as it gets, however can you please let me
> > know how to declare a Sub() which includes optional parameters eg:

> > Sub MyRoutine(param1, param2, param3)

> > End Sub

> > Where param 3 has a default value lets say ("") an empty string...

> > All help appreciated

> > Thanks in advance

> > Ian James

> Scripting does NOT support this.  One common work around is to use a
> single array as the argument and then to have logic in the subroutine to
> parse out the proper arguments.  The other is to concatenate the
> arguments into a string with a delimiter and then use Split to parse off
> the supplied arguments.  I posted a response recently that has an
> example, if you care to search for it.

> Tom Lavedas
> -----------
> http://www.pressroom.com/~tglbatch/

I agree with TL.  I belong to the delimited string culture myself
(particularly for script-generated HTML).

The single-array method has merit where passed params are few in number, but
it does require that both the caller and the called routine know and observe
the ordinal structure in the argument.

Delimited strings are more flexible, and with a compound delimiter you can
store the output from Split in a Dictionary object for ultra-easy access.
Take this:

arg = "param1=value1,param2=value2,param3=value3"

Splitting on the commas produces an array of substrings which are themselves
splittable at the "=".
Now split each element into a Dictionary key and value, and the business of
addressing parameters becomes a walk in the park.

I can vouch for this where large numbers of parameters are involved, such as
when DHTML elements are created with compound attributes initialized by
script.

Think about it:  you might even want to pass a Dictionary as the argument?
Groovy or what?

It may not be the quickest way about it, but then if speed matters why use
VBScript?

:)
Jeff Morris



Sun, 11 May 2003 03:00:00 GMT  
 Optional Parameters
Ahhh... your last sentence has me thinking is this possible in
javascript...? or are you thinkingof something else all together...?

Thanks for the replies (Tom also...)

Regards

Ian James


Quote:




> > > I am sure this is as basic as it gets, however can you please let me
> > > know how to declare a Sub() which includes optional parameters eg:

> > > Sub MyRoutine(param1, param2, param3)

> > > End Sub

> > > Where param 3 has a default value lets say ("") an empty string...

> > > All help appreciated

> > > Thanks in advance

> > > Ian James

> > Scripting does NOT support this.  One common work around is to use a
> > single array as the argument and then to have logic in the subroutine to
> > parse out the proper arguments.  The other is to concatenate the
> > arguments into a string with a delimiter and then use Split to parse off
> > the supplied arguments.  I posted a response recently that has an
> > example, if you care to search for it.

> > Tom Lavedas
> > -----------
> > http://www.pressroom.com/~tglbatch/

> I agree with TL.  I belong to the delimited string culture myself
> (particularly for script-generated HTML).

> The single-array method has merit where passed params are few in number,
but
> it does require that both the caller and the called routine know and
observe
> the ordinal structure in the argument.

> Delimited strings are more flexible, and with a compound delimiter you can
> store the output from Split in a Dictionary object for ultra-easy access.
> Take this:

> arg = "param1=value1,param2=value2,param3=value3"

> Splitting on the commas produces an array of substrings which are
themselves
> splittable at the "=".
> Now split each element into a Dictionary key and value, and the business
of
> addressing parameters becomes a walk in the park.

> I can vouch for this where large numbers of parameters are involved, such
as
> when DHTML elements are created with compound attributes initialized by
> script.

> Think about it:  you might even want to pass a Dictionary as the argument?
> Groovy or what?

> It may not be the quickest way about it, but then if speed matters why use
> VBScript?

> :)
> Jeff Morris




Sun, 11 May 2003 03:00:00 GMT  
 Optional Parameters
arguments Property [of the currently executing JScript function]
http://msdn.microsoft.com/scripting/jscript/doc/jsproArguments.htm

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup...
--


Quote:
> Ahhh... your last sentence has me thinking is this possible in
> javascript...? or are you thinkingof something else all together...?

> Thanks for the replies (Tom also...)

> Regards

> Ian James






> > > > I am sure this is as basic as it gets, however can you please let me
> > > > know how to declare a Sub() which includes optional parameters eg:

> > > > Sub MyRoutine(param1, param2, param3)

> > > > End Sub

> > > > Where param 3 has a default value lets say ("") an empty string...

> > > > All help appreciated

> > > > Thanks in advance

> > > > Ian James

> > > Scripting does NOT support this.  One common work around is to use a
> > > single array as the argument and then to have logic in the subroutine to
> > > parse out the proper arguments.  The other is to concatenate the
> > > arguments into a string with a delimiter and then use Split to parse off
> > > the supplied arguments.  I posted a response recently that has an
> > > example, if you care to search for it.

> > > Tom Lavedas
> > > -----------
> > > http://www.pressroom.com/~tglbatch/

> > I agree with TL.  I belong to the delimited string culture myself
> > (particularly for script-generated HTML).

> > The single-array method has merit where passed params are few in number,
> but
> > it does require that both the caller and the called routine know and
> observe
> > the ordinal structure in the argument.

> > Delimited strings are more flexible, and with a compound delimiter you can
> > store the output from Split in a Dictionary object for ultra-easy access.
> > Take this:

> > arg = "param1=value1,param2=value2,param3=value3"

> > Splitting on the commas produces an array of substrings which are
> themselves
> > splittable at the "=".
> > Now split each element into a Dictionary key and value, and the business
> of
> > addressing parameters becomes a walk in the park.

> > I can vouch for this where large numbers of parameters are involved, such
> as
> > when DHTML elements are created with compound attributes initialized by
> > script.

> > Think about it:  you might even want to pass a Dictionary as the argument?
> > Groovy or what?

> > It may not be the quickest way about it, but then if speed matters why use
> > VBScript?

> > :)
> > Jeff Morris




Mon, 12 May 2003 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Optional parameter in jscript. (Variant optional - DISP_E_PARAMNOTFOUND)

2. Using Parameter Queries with Optional Parameters

3. passing optional parameters to the parameters collection

4. Writing A Function with optional parameters

5. how to declare a function with optional parameters

6. how to make array an optional parameter

7. Function overloading and Optional parameters

8. Inheritance across VB assemblies: Optional parameter compiler problem

9. Default value in optional parameter

10. C# optional parameters

11. Optional Parameters.

12. DataEnvironment Command with Optional Parameter problem in Oracle

 

 
Powered by phpBB® Forum Software