Help, OA ByRef parameters not passed correctly 
Author Message
 Help, OA ByRef parameters not passed correctly

Help!  My by-reference parameters aren't being passed back to SQL Server
(MSSS2KEnt) correctly using OLE Automation.  I am using components written
in Windows Scripting Host.

Here are the good bits (but I'm pretty sure some of the proper surrounding
guts are missing.)

The class declares a public method function, getSomething(), that returns an
integer as the function result and modifies the single byref paramter to "Hi
there", forced to be a string (as if it weren't already).

When I instantiate and test the object from a WSF, everything works.
When I instantiate and test the object from a SQL script, the string comes
back blank.  Not null, but as a blank string.

What do I need to do to get my modified paramters back?

Thanks,
    - Dan

ProcessingManager.WSC
====================
<package>

    <component id="TR.ProcessingManager">
        <public>
            <method name="getSomething">
                <parameter name="astring"/>
            </method>
        </public>
        <script language="VBScript">
            function getSomething(byref astring)
                astring = CStr("Hi there")
                getSomething = 3
            end function
    </script>

    </component>
</package>

Test.WSF
==========
<object id="PM" progid="TR.ProcessingManager"/>
<script language="VBScript">
        res = PM.getSomething(astr)
        WScript.echo "Something (" & res & "): " & astr
</script>

Test.SQL
==========



:

output



Wed, 25 Feb 2004 15:29:16 GMT  
 Help, OA ByRef parameters not passed correctly
Your WSC methods can accept and modify by reference arguments as long as (and only if) the caller
passes a variant argument.

In the WSF test, all a WSF can possibly pass is a variant.

In your SQL script, it would appear that you are passing strongly typed arguments (I don't really
know SQL script syntax ;-).  The net effect is that the argument is effectively coerced to pass by
value.

--

Michael Harris
Microsoft.MVP.Scripting
--

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

Quote:

> Help!  My by-reference parameters aren't being passed back to SQL Server
> (MSSS2KEnt) correctly using OLE Automation.  I am using components written
> in Windows Scripting Host.

> Here are the good bits (but I'm pretty sure some of the proper surrounding
> guts are missing.)

> The class declares a public method function, getSomething(), that returns an
> integer as the function result and modifies the single byref paramter to "Hi
> there", forced to be a string (as if it weren't already).

> When I instantiate and test the object from a WSF, everything works.
> When I instantiate and test the object from a SQL script, the string comes
> back blank.  Not null, but as a blank string.

> What do I need to do to get my modified paramters back?

> Thanks,
>     - Dan

> ProcessingManager.WSC
> ====================
> <package>

>     <component id="TR.ProcessingManager">
>         <public>
>             <method name="getSomething">
>                 <parameter name="astring"/>
>             </method>
>         </public>
>         <script language="VBScript">
>             function getSomething(byref astring)
>                 astring = CStr("Hi there")
>                 getSomething = 3
>             end function
>     </script>

>     </component>
> </package>

> Test.WSF
> ==========
> <object id="PM" progid="TR.ProcessingManager"/>
> <script language="VBScript">
>         res = PM.getSomething(astr)
>         WScript.echo "Something (" & res & "): " & astr
> </script>

> Test.SQL
> ==========



> :

> output




Thu, 26 Feb 2004 01:40:15 GMT  
 Help, OA ByRef parameters not passed correctly
Quote:
>...modify by reference arguments...only if..the caller passes a variant...

That is a good thing to know, and gives me a good starting point.

Quote:
>...you are passing strongly typed arguments...

I'm certain that is the case with SQL Server's OLE Automation interface.
Now I just have to figure out how to "strongly-type" to a variant in SQL
Server.   (And, sql_variant doesn't do it.)

Thanks, again,
    - Dan



Quote:
> Your WSC methods can accept and modify by reference arguments as long as

(and only if) the caller
Quote:
> passes a variant argument.

> In the WSF test, all a WSF can possibly pass is a variant.

> In your SQL script, it would appear that you are passing strongly typed

arguments (I don't really
Quote:
> know SQL script syntax ;-).  The net effect is that the argument is

effectively coerced to pass by
Quote:
> value.

> --

> Michael Harris
> Microsoft.MVP.Scripting
> --

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



Quote:
> > Help!  My by-reference parameters aren't being passed back to SQL Server
> > (MSSS2KEnt) correctly using OLE Automation.  I am using components
written
> > in Windows Scripting Host.

> > Here are the good bits (but I'm pretty sure some of the proper
surrounding
> > guts are missing.)

> > The class declares a public method function, getSomething(), that
returns an
> > integer as the function result and modifies the single byref paramter to
"Hi
> > there", forced to be a string (as if it weren't already).

> > When I instantiate and test the object from a WSF, everything works.
> > When I instantiate and test the object from a SQL script, the string
comes
> > back blank.  Not null, but as a blank string.

> > What do I need to do to get my modified paramters back?

> > Thanks,
> >     - Dan

> > ProcessingManager.WSC
> > ====================
> > <package>

> >     <component id="TR.ProcessingManager">
> >         <public>
> >             <method name="getSomething">
> >                 <parameter name="astring"/>
> >             </method>
> >         </public>
> >         <script language="VBScript">
> >             function getSomething(byref astring)
> >                 astring = CStr("Hi there")
> >                 getSomething = 3
> >             end function
> >     </script>

> >     </component>
> > </package>

> > Test.WSF
> > ==========
> > <object id="PM" progid="TR.ProcessingManager"/>
> > <script language="VBScript">
> >         res = PM.getSomething(astr)
> >         WScript.echo "Something (" & res & "): " & astr
> > </script>

> > Test.SQL
> > ==========



> > :

> > output




Thu, 26 Feb 2004 02:21:04 GMT  
 Help, OA ByRef parameters not passed correctly
Dan,

Are you on sql7 or 2k?  Sql2k allows sql_variant datatype. This is similar
to VB Variant.

-oj


Quote:
> >...modify by reference arguments...only if..the caller passes a
variant...
> That is a good thing to know, and gives me a good starting point.

> >...you are passing strongly typed arguments...
> I'm certain that is the case with SQL Server's OLE Automation interface.
> Now I just have to figure out how to "strongly-type" to a variant in SQL
> Server.   (And, sql_variant doesn't do it.)

> Thanks, again,
>     - Dan



> > Your WSC methods can accept and modify by reference arguments as long as
> (and only if) the caller
> > passes a variant argument.

> > In the WSF test, all a WSF can possibly pass is a variant.

> > In your SQL script, it would appear that you are passing strongly typed
> arguments (I don't really
> > know SQL script syntax ;-).  The net effect is that the argument is
> effectively coerced to pass by
> > value.

> > --

> > Michael Harris
> > Microsoft.MVP.Scripting
> > --

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


> > > Help!  My by-reference parameters aren't being passed back to SQL
Server
> > > (MSSS2KEnt) correctly using OLE Automation.  I am using components
> written
> > > in Windows Scripting Host.

> > > Here are the good bits (but I'm pretty sure some of the proper
> surrounding
> > > guts are missing.)

> > > The class declares a public method function, getSomething(), that
> returns an
> > > integer as the function result and modifies the single byref paramter
to
> "Hi
> > > there", forced to be a string (as if it weren't already).

> > > When I instantiate and test the object from a WSF, everything works.
> > > When I instantiate and test the object from a SQL script, the string
> comes
> > > back blank.  Not null, but as a blank string.

> > > What do I need to do to get my modified paramters back?

> > > Thanks,
> > >     - Dan

> > > ProcessingManager.WSC
> > > ====================
> > > <package>

> > >     <component id="TR.ProcessingManager">
> > >         <public>
> > >             <method name="getSomething">
> > >                 <parameter name="astring"/>
> > >             </method>
> > >         </public>
> > >         <script language="VBScript">
> > >             function getSomething(byref astring)
> > >                 astring = CStr("Hi there")
> > >                 getSomething = 3
> > >             end function
> > >     </script>

> > >     </component>
> > > </package>

> > > Test.WSF
> > > ==========
> > > <object id="PM" progid="TR.ProcessingManager"/>
> > > <script language="VBScript">
> > >         res = PM.getSomething(astr)
> > >         WScript.echo "Something (" & res & "): " & astr
> > > </script>

> > > Test.SQL
> > > ==========



> > > :

> > > output




Thu, 26 Feb 2004 02:36:05 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Help, OA ByRef parameters not passed correctly

2. passing ByRef parameters

3. Passing Byref parameter to an ocx method

4. > passing vb6 optional byref parameter into c#

5. Passing Parameters - A ByRef vs ByVal Question

6. Passing a ByRef parameter

7. Passing parameters ByRef or ByVal

8. variable not passed correctly

9. variable not passed correctly

10. ByRef or not ByRef, that is the array?

11. Property Let argument ByRef is NOT ByRef ?

12. AddCurrentValue not working correctly for boolean parameters

 

 
Powered by phpBB® Forum Software