We help IT Professionals succeed at work.
Get Started

COM object preserve values between invocations

Last Modified: 2016-04-28
in VB 2008 I create managed com object, which I then call from an application. The application runs vbscript* where it's using CreateObject for my object.

In COM object I have a Module with Friend variable, which value is set at the execution time.

If I then run the script 2nd time, I found that the variable in the COM object already has previous value. I expected that CreateObject would re-initialize it.

run the script
   set M = createobject("myapp.myobject")
                                                                                 Friend X as string
                                                                                 X = "myvalue"
  Set M = Nothing

run the script again
   set M = createobject("myapp.myobject")
                                                                                 Friend X as string

At this point, X in the object will already have "Myvalue".

Does anybody know where is this behavior documented? I expected that "createobject" would indeed create new object from scratch, rather than reuse the old one; especially after prior Set M = Nothing

*) The application is using its own script engine based on vbscript. Microsoft used to license VBscript engine to 3rd parties, so they incorporated it in their own product. This is one of them.
Watch Question
Distinguished Expert 2017
This problem has been solved!
Unlock 2 Answers and 7 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE