Function func1(Parm1, Optional Parm2)
'...
End Function
Can I create a function in VBScript / ASP that carries an OPTIONAL
parameter?
Thanks.
But you can pass in an array as your parm with one or more values whihc
makes the function contain optional values.
Or you can pass in a string with seperators dividing your optional values.
Either way you only need to count your values to determine what to do within
your function - the array is the cleaner approach.
regards
John Timney (MVP)
Software Dev <s...@nospam.com> wrote in message
news:Or5$VIU4$GA.1876@cpmsftngp03...
I'm hoping it will appear in ASP 3.0 (along with the Format
Function??), but the notes in the back of my book don't
mention it specifically. Of course, Com Component Methods can
use them, but that's a whole new ball game.
HTH,
Phill W.
Software Dev wrote:
> . . . Can I create a function in VBScript / ASP that carries an
> OPTIONAL parameter? . . .
a) <pedant> ASP doesn't support functions at all - that's the job of the
scripting engine (in this case, VBScript) </pedant>
b) The latest version of VBScript (from WSH2 - present in Win2000 and
installable on other platforms, *unlike ASP3* which you seem to believe
would update VBS - ASP3 is only available on Win2K and is almost certainly
going to stay that way; WSH2 and versions of VBS, however, are installable
on any Win9x / 2000 platform, even if it's not running anything that
supports ASP) **does not support optional arguments** (or Format(), as you
mentioned it)
Try [ http://msdn.microsoft.com/scripting ] and look at the tables in the
VBScript documentation.
hth hand
Adam
myFunc(arg1)
myFunc(arg1, arg2...argn)
This can be done by creating the function in J/JavaScript and calling it
from VBScript. Furthermore, putting it in a script component hides the
ugliness of using another language. I'd be more than happy to code up a
solution for you if you want to give me some details of what you want to do
in the function(s). (It'll take more than 5 minutes so I need to know if
anyone wants it first. Real problems are the most useful examples).
Again, the reason to do this is to use functions with optional numbers of
parameters. J/JavaScript optional parameters are functionally equivalent to
VB's except that J/JavaScript functions have no notion of listing a blank
parameter. As others in this group have suggested, there are many ways of
getting the job done by passing in arrays or using global data but those are
not complete solutions.
I am currently trying to figure out how to programmatically convert VBScript
such as the following into JScript:
Set oRec = Server.CreateObject("ADODB.Record")
oRec.Open , , , , ,"UserID", "Password"
The first statement is a breeze. The second line is a puzzler and is related
to your question. Although VBScript cannot create procedures with optional
arguments it does provide the syntax to call procedures with optional
parameterization. I have no idea how to convert this VBScript statement
with empty commas to equivalent J/JavaScript. In C/C++, I could create a
special variant to pass into the blank parameter slots which would tell the
interperter to use the default values for those parameters which is
essentially what an optional parameter is all about--it is a way to declare
and simplify default values and makes sense . Of course, I can get the job
done in JScript using other methods but that is hardly the same as
translating a statement from VBScript to JScript.
"Software Dev" <s...@nospam.com> wrote in message
news:Or5$VIU4$GA.1876@cpmsftngp03...
> In VB, I can do the following to create a function with an optional
> parameter:
>
> Function func1(Parm1, Optional Parm2)
> '...
> End Function
>
> Can I create a function in VBScript / ASP that carries an OPTIONAL
> parameter?
>
> Thanks.
>
>