This project has moved and is read-only. For the latest updates, please go here.

VBScript ByRef arguments cannot seem to get to work.

Nov 21, 2014 at 7:55 PM
Sorry I added a item to the issues, but probably should have been posted here instead..

Great Library, really helpful!

I ran into one situation where we have some existing VBScripts, the have subroutines and functions that take ByRef scalar types such as ints, double and the values are being changed in the function.

Here is the code I tested:
    VBScriptEngine scriptEngine = new VBScriptEngine(WindowsScriptEngineFlags.EnableDebugging);
    double byRefValue = 10.0;
    scriptEngine.Execute(@"sub TestSub(ByRef MyParam) : MyParam=20.0 : end sub");
    scriptEngine.Script.TestSub(ref byRefValue);

Basically what I was trying to accomplish , was the double values should end up being set to 20.0 , but it always remains at 10.0

I tried changing the double to an object and dynamic and it didn't make a difference.

Any thoughts on how to support this scenario.

Nov 24, 2014 at 5:20 PM

By-reference arguments to VBScript functions are not currently supported. We'll use the work item you created to track this issue. Thanks for reporting it!

In the meantime, you can create a wrapper in VBScript that calls the target function and returns its output to the host without by-reference parameters. For example:
public class Holder<T> {
    public T Value;
And then:
    sub TestSubWrapper(holder)
        dim value
        value = holder.Value
        call TestSub(value)
        holder.Value = value
    end sub

var holder = new Holder<double> { Value = 10.0 };
Thanks again, and good luck!