I am writing a simple scripting engine. I would like to base this engine off of the Ms Script control.
I need to have the VbScript code in the control access a different object each time it's run. So instead of adding the actual object to the control I add a reference that points to the actual object. However, the control seems to take the actual object instead of the reference.
Here is some testing code. sc is the script control. clsTest is a class module that contains "Public a as long".
VB Code:
sc.AddCode "sub main" & vbNewLine & " msgbox ref.a" & vbNewLine & "end sub" Dim obj(5) As New clstest Dim counter As Byte For counter = 0 To 5 obj(counter).a = counter 'makes each element different Next counter Dim ref As clstest Set ref = obj(0) sc.AddObject "ref", ref 'add the REFERENCE object sc.Run "main" 'makes a message box with 0 MsgBox ref.a 'displays 0 Set ref = obj(3) sc.Run "main" 'should make a messagebox with 3, but makes it with 0 MsgBox ref.a 'displays 3
After I set ref = obj(3) I want the script control to access obj(3), but it only accesses obj(0).
Why is it doing this and how can I fix it?
Thanks!




Reply With Quote