Link to home
Start Free TrialLog in
Avatar of mholywell
mholywell

asked on

script control accessing variables

The documentation on Microsofts web site suggests script control can be used to update variables..

why when I try scriptcontrol1.executestatement "x=100"
does nothing happen

I've tried sc.addcode:

sub inc(x)
x=x+1
msgbox(x)
end sub

and sure enough the messagebox shows x(on call)+1 but x isn't updated in my program.. and I've tried byref x.

And, finally, I've repeated the test as JScript.

Is the documentation misleading or am I being stupid?
Avatar of ameba
ameba
Flag of Croatia image

Private Sub Command1_Click()
    On Error GoTo runerr
' Add the code, then run the function.
    ScriptControl1.AddCode Text1.Text
    Dim ret As String
    ret = ScriptControl1.Run("inc")
    MsgBox ret, vbOKOnly, "Function returned"
    Debug.Print ret
    Exit Sub
runerr:
    Exit Sub
End Sub

' in your script, add
   inc = x
Documentation (help file) is a bit hidden, but try:
   winhelp MSScript
in the Run dialog (Start, Run)
Avatar of mholywell
mholywell

ASKER

To Ameba:  Thanks..

The pointer to the documentation was handy - it looks like I've got to use .addobject if I want to return multiple values from my routine but I can't get executeStatement to work as per their example.

I'm working on create object and call to get round my earlier problem Q.10149829 but calls from within a vbscript appear to be byval (though the strong typing problem goes away!)

Claim the points.. but if you want a problem to solve try call byref from within a vbscript!
ASKER CERTIFIED SOLUTION
Avatar of ameba
ameba
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This script control seems to do everything except allow me to get round my callbyname problem...

I will continue the search!

Thanks