Passing arguments ByRef to Script Control 1.0 
Author Message
 Passing arguments ByRef to Script Control 1.0

Anybody know if you can pass an argument ByRef to a script with the Scrip
Control 'Run' method?  Ie:

  'Make a script function
  Dim strFunction As String
  strFunction = _
  "Function ReturnThis(x, ByRef y)" & vbCrLf & _
  " ReturnThis = x * y" & vbCrLf & _
  " y = 5" & vbCrLf & _
  "End Function"
  ' Get ready to call it
  Dim x As Integer, y As Integer
  ScriptControl1.AddCode strFunction
  x = 2: y = 3
  MsgBox ScriptControl1.Run("ReturnThis", x, y)
  MsgBox y  'still appears to be 3

When I change the y parameter in the ReturnThis script function, the y
variable in the host doesn't seem to change.  Does this mean no ByVal for
me?


-Richard K.



Wed, 10 Sep 2003 19:28:09 GMT  
 Passing arguments ByRef to Script Control 1.0
Use the CodeObject object instead of the Run method.  All procedures added to the default "Global"
module are exposed as public methods of a CodeObject object returned by the script control's
CodeObject property...

  'Make a script function
  Dim strFunction As String
  strFunction = _
  "Function ReturnThis(x, ByRef y)" & vbCrLf & _
  " ReturnThis = x * y" & vbCrLf & _
  " y = 5" & vbCrLf & _
  "End Function"
  ' Get ready to call it
  Dim x As Integer, y As Integer
  ScriptControl1.AddCode strFunction
  x = 2: y = 3
  MsgBox ScriptControl1.CodeObject.ReturnThis(x, y)
  MsgBox y

If you use explictly named modules (...Modules.Add("MyModule"") ), then each named module has it's
own CodeObject property.

--
Michael Harris
Microsoft.MVP.Scripting
--

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

Quote:

> Anybody know if you can pass an argument ByRef to a script with the Scrip
> Control 'Run' method?  Ie:

>   'Make a script function
>   Dim strFunction As String
>   strFunction = _
>   "Function ReturnThis(x, ByRef y)" & vbCrLf & _
>   " ReturnThis = x * y" & vbCrLf & _
>   " y = 5" & vbCrLf & _
>   "End Function"
>   ' Get ready to call it
>   Dim x As Integer, y As Integer
>   ScriptControl1.AddCode strFunction
>   x = 2: y = 3
>   MsgBox ScriptControl1.Run("ReturnThis", x, y)
>   MsgBox y  'still appears to be 3

> When I change the y parameter in the ReturnThis script function, the y
> variable in the host doesn't seem to change.  Does this mean no ByVal for
> me?


> -Richard K.



Thu, 11 Sep 2003 06:28:35 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing arguments ByRef from VBScript to COMAdmin component

2. Pass arguments ByVal or ByRef

3. Passing arguments byref to a class

4. Property Let argument ByRef is NOT ByRef ?

5. How to pass control array ByRef?

6. Passing a control array byRef ??

7. passing a control array byref

8. JScript, Event Interfaces, and ByRef arguments

9. ByRef arguments

10. VBScript ByRef argument to VB DLL in IIS-5

11. Arguments : Passing Arguments containing <">

12. Passing control from VB to VB Script -- need to access SetFocus in script

 

 
Powered by phpBB® Forum Software