Calling a COM Method with optional arguments from ASP 
Author Message
 Calling a COM Method with optional arguments from ASP

I am calling a function that accepts optional arguments

    Public Function Test(ByVal key as long, Optional arg1 as string = "",
Optional arg2 as string = "")
        ...
    End Function

If I was calling this function in VB6 if I didn't want to send a value to
'arg1' I would do this

    flag = obj.Test(1000,arg2:="Some Text")

When I try this syntax from my ASP page I get an error.  Is this possible
from ASP with different syntax?  How would I do this?

Thanks in advance,

Mike



Wed, 23 Feb 2005 03:02:44 GMT  
 Calling a COM Method with optional arguments from ASP
I'm not sure whether ASP (VBScript) supports named arguments or not, but
this one definately works:

    flag = obj.Test(1000, , "Some Text")

--
Bj?rn Holmgren
Guide Konsult AB


Quote:
> I am calling a function that accepts optional arguments

>     Public Function Test(ByVal key as long, Optional arg1 as string = "",
> Optional arg2 as string = "")
>         ...
>     End Function

> If I was calling this function in VB6 if I didn't want to send a value to
> 'arg1' I would do this

>     flag = obj.Test(1000,arg2:="Some Text")

> When I try this syntax from my ASP page I get an error.  Is this possible
> from ASP with different syntax?  How would I do this?

> Thanks in advance,

> Mike



Wed, 23 Feb 2005 03:11:35 GMT  
 Calling a COM Method with optional arguments from ASP

Quote:
> I am calling a function that accepts optional arguments

>    Public Function Test(ByVal key as long, Optional arg1 as string = "",
> Optional arg2 as string = "")
>        ...
>    End Function
[...]
> When I try this syntax from my ASP page I get an error.  Is
> this possible from ASP with different syntax?  How would I do this?

Grr. *ASP* doesn't _have_ any concept of syntax, since it's not a
language, it's a framework within which a number of languages can
execute.

Assuming you meant VBScript, then you can't use named or optional
arguments, since they are unsupported. You'll have to supply values for
each of the arguments.

hth

Adam
--
Manly's Maxim:
        Logic is a systematic method of coming to the wrong conclusion
        with confidence.



Wed, 23 Feb 2005 17:35:25 GMT  
 Calling a COM Method with optional arguments from ASP
Yes, using VBScript from ASP does allow you to call COM components that
expose methods with optional parameters.  I do not believe you can use named
arguments, but the following should work.

dim objTest, message, id
message = "Some Text"
id = 1000
Set objTest = Server.CreateObject("MyCOMLib.MyCoClass")
objTest.Test(id,,message)
Set objTest = Nothing

I would, however, specify the optional parameters as ByVal, meaning if they
are passed at all, they are passed ByVal (since the default is ByRef).  ASP
will bark because it does not have a string type to send to the COM object.
The alternative would be to use Variants in the COM class' method signature
(you lose defaults but that should be a preference and not a necessity).
The other option is to cast the arguments in ASP before calling COM:

objTest.Test(clng(id),,cstr(message))

The caveat to this approach is that you cannot access the new value of "id"
or "message" if they are changed in the body of the COM method.  If you want
to change the value of the parameter in COM and pass it back to ASP, then
you need to declare the parameter ByRef as Variant in COM.  Note that you
will get better performane simply by returning a structure instead.

--
Kirk Allen Evans
http://www.xmlandasp.net
Author, "XML And ASP.NET", New Riders Publishing
http://www.amazon.com/exec/obidos/ASIN/073571200X


Quote:
> I am calling a function that accepts optional arguments

>     Public Function Test(ByVal key as long, Optional arg1 as string = "",
> Optional arg2 as string = "")
>         ...
>     End Function

> If I was calling this function in VB6 if I didn't want to send a value to
> 'arg1' I would do this

>     flag = obj.Test(1000,arg2:="Some Text")

> When I try this syntax from my ASP page I get an error.  Is this possible
> from ASP with different syntax?  How would I do this?

> Thanks in advance,

> Mike



Thu, 24 Feb 2005 04:43:51 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Calling a COM Method with optional arguments from ASP

2. Optional Arguments For A .WSC-Defined Method

3. Performance of ASP pages calling COM object methods

4. Performance of ASP pages calling COM object methods

5. asp/vbscript/vb optional procedure arguments not passed....

6. Argument Not Optional: ac97, calling a function

7. Calling a COM object from VB.Net with Optional Params

8. Calling a COM call back object's method fails if it is in Windows 98

9. com object will not read registry when com object called from asp (vb works fine)

10. Need help passing arguments to a COM method...

11. How to check proceedings of COM method from ASP

12. http://www1.askme.com/MyXpertise.asp?cid=1044&method=qb

 

 
Powered by phpBB® Forum Software