Redefine a class or function

217 Views Asked by At

I have to add a VBScript interface to our C# app and have completed this with ScriptControlClass (MS Scripting Engine). However, I am not too familiar with VBS and can't find a solution to this:

If I define a class then decide to make a change to that class, when I run the code for the class a second time I get the error:

Name redefined

Example:

  1. Define a Class (ex: Class test .... End Class)
  2. "Compile" (from C# code, call ScriptControlClass.AddCode(code_for_class))
  3. Make a change to the class's code
  4. "Compile" again - get error here

How do I "undefine" the class before trying to compile?

Also, I am not asking about how toDim or Redim an object of that class. I want to modify the class code.

1

There are 1 best solutions below

1
On

Script code is not "compiled", it is executed when you call AddCode()

All of the code you add is known by the scriptcontrol until you do Reset(). Resetting makes the scriptcontrol remove all the code that has been added.

So you'll first have to Reset() before you add the code for the same class again.