Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

script control accessing variables

Posted on 1999-06-22
6
Medium Priority
?
483 Views
Last Modified: 2012-08-14
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?
0
Comment
Question by:mholywell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 15

Expert Comment

by:ameba
ID: 1518922
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
0
 
LVL 15

Expert Comment

by:ameba
ID: 1518923
Documentation (help file) is a bit hidden, but try:
   winhelp MSScript
in the Run dialog (Start, Run)
0
 

Author Comment

by:mholywell
ID: 1518924
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!
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 15

Accepted Solution

by:
ameba earned 400 total points
ID: 1518925
>I want to return multiple values from my routine

' Add this component: Microsoft Script control 1.0
' Add textbox (Multiline=true), command button, ScriptControl
' Paste this code
Option Explicit

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("MyCode")
    MsgBox ret, vbOKOnly, "Function returned"
' get variables
    MsgBox ScriptControl1.Eval("a")
    MsgBox ScriptControl1.Eval("b")
    MsgBox ScriptControl1.Eval("x")
    Debug.Print ret
    Exit Sub
runerr:
    Exit Sub
End Sub

Private Sub Form_Load()
    Dim pgm As String
    pgm = _
        "Dim a, b, x" & vbCrLf & _
        "Public Function MyCode()" & vbCrLf & _
        "   a = 5" & vbCrLf & _
        "   b = 55" & vbCrLf & _
        "   x = a + b" & vbCrLf & _
        "   MyCode = x" & vbCrLf & _
        "End Function" & vbCrLf
    'Text1.FontName = "Fixedsys"
    Text1.Text = pgm
End Sub

Private Sub Form_Resize()
    On Error Resume Next
    Text1.Move 0, 0, ScaleWidth, ScaleHeight - Command1.Height
    Command1.Move (ScaleWidth - Command1.Width) / 2, ScaleHeight - Command1.Height
End Sub

Private Sub ScriptControl1_Error()
    With ScriptControl1.Error
        MsgBox .Number & _
            ":" & .Description & vbCrLf & _
            " in line " & .Line
    End With
End Sub
0
 

Author Comment

by:mholywell
ID: 1518926
This script control seems to do everything except allow me to get round my callbyname problem...

I will continue the search!

Thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question