Results 1 to 5 of 5

Thread: MsScript.AddObject

  1. #1

    Thread Starter
    Addicted Member imbue's Avatar
    Join Date
    Aug 2002
    Location
    Midwest USA
    Posts
    155

    Angry 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:
    1. sc.AddCode "sub main" & vbNewLine & " msgbox ref.a" & vbNewLine & "end sub"
    2.  
    3. Dim obj(5) As New clstest
    4.  
    5. Dim counter As Byte
    6. For counter = 0 To 5
    7. obj(counter).a = counter 'makes each element different
    8. Next counter
    9.  
    10. Dim ref As clstest
    11. Set ref = obj(0)
    12.  
    13. sc.AddObject "ref", ref 'add the REFERENCE object
    14.  
    15. sc.Run "main" 'makes a message box with 0
    16. MsgBox ref.a 'displays 0
    17.  
    18.  
    19. Set ref = obj(3)
    20. sc.Run "main" 'should make a messagebox with 3, but makes it with 0
    21. 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!

  2. #2

    Thread Starter
    Addicted Member imbue's Avatar
    Join Date
    Aug 2002
    Location
    Midwest USA
    Posts
    155
    any ideas?

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    VB Code:
    1. Set ref = obj(0)
    2.  
    3. 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:
    1. sc.AddCode "sub main" & vbNewLine & " msgbox ref.a" & vbNewLine & "end sub"
    2.  
    3. Dim obj(5) As New clstest
    4.  
    5. Dim counter As Byte
    6. For counter = 0 To 5
    7. obj(counter).a = counter 'makes each element different
    8. Next counter
    9.  
    10. Dim ref As clstest
    11. Set ref = obj(0)
    12.  
    13. sc.AddObject "ref", ref 'add the REFERENCE object
    14.  
    15. sc.Run "main" 'makes a message box with 0
    16. MsgBox ref.a 'displays 0
    17.  
    18.  
    19. Set ref = obj(3)
    20.  
    21. sc.AddObject "ref", ref 'add the REFERENCE object
    22.  
    23. sc.Run "main" 'should make a messagebox with 3, but makes it with 0
    24. 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....
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Addicted Member imbue's Avatar
    Join Date
    Aug 2002
    Location
    Midwest USA
    Posts
    155
    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 Attached Images  

  5. #5

    Thread Starter
    Addicted Member imbue's Avatar
    Join Date
    Aug 2002
    Location
    Midwest USA
    Posts
    155

    Question

    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
  •  



Click Here to Expand Forum to Full Width