Jan 17th, 2003, 02:43 AM
#1
Thread Starter
Addicted Member
MsScript.AddObject
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!
Jan 17th, 2003, 01:28 PM
#2
Thread Starter
Addicted Member
Jan 17th, 2003, 01:40 PM
#3
VB Code:
Set ref = obj(0)
sc.AddObject "ref", ref 'add the REFERENCE object
You add the object obj(0).... if you want it to ref obj(3), then you need to add it....
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.AddObject "ref", ref 'add the REFERENCE object
sc.Run "main" 'should make a messagebox with 3, but makes it with 0
MsgBox ref.a 'displays 3
It added obj(0) to the Engine, but resetting the reference doesn't change the reference in the script engine....
Jan 17th, 2003, 01:49 PM
#4
Thread Starter
Addicted Member
I tried that before, but it seems that I cannot add the same object name more than once.
I get this error message when adding "ref" for the second time.
Attached Images
Jan 17th, 2003, 09:58 PM
#5
Thread Starter
Addicted Member
Well is there any way to do it?
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width