Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: An example to share vb6 script control vs clearscript

0
0
In my current VB6 app I use scripting to plug in classes that the scripting can maniplate and also call functions within my plugged in classes to effect change and act as events in my main app. This is a bit of test code that shows the same capacity in clearscript.

VB6 EXAMPLE

SIMPLE CLASS VBStest

public A as Long
publc B as Long


Set SC = New ScriptControl
SC.AllowUI = False
SC.Language = "VBScript"
SC.Reset

Set TEST1 = New VBStest
TEST1.A = 1000
TEST1.B = 2000
SC.AddObject "TEST1", TEST1, True

newCode = "Public Sub addtoTEST1A(inval)" & _
"    TEST1.A = TEST1.A + inval" & _
        "End Sub"
SC.AddCode newCode

T1 = new VBStest;
T1.A = 3000
T1.B = 4000
TEST1 = T1;

SC.RUN "addtoTEST1A(" & 5000 & ")"

' TEST1.A is now 8000

CLEARSCRIPT

public class V8test
{

  public int A = 0;
  public int B = 0; 

}

public void testV8()
{

    V8ScriptEngine V8JS = new V8ScriptEngine();
string newCode = @"
var TEST1;

function setTEST1(inval)
{
    TEST1 = inval;
}

function addtoTEST1A(inval)
{
   TEST1.A += inval;
}
";
    V8JS.Execute(newCode);

            V8test T1 = new V8test();
            T1.A = 3000;
    T1.B = 4000;

    // V8JS.Script.TEST1 = T1; did not work at setting to new object
            V8JS.Script.setTEST1(T1);

            V8JS.Script.TEST1.A += 5000;

          // T1.A and V8JS.Script.TEST1.A are same object, value 8000

          V8test T2 = new V8test();
          T2.A = 1000;
      T2.B = 2000;

          V8JS.Script.setTEST1(T2);

          V8JS.Script.addtoTEST1A(3000);

          // T2.A and V8JS.Script.TEST1.A are same object, value 4000

}

Viewing all articles
Browse latest Browse all 2297