Using a script engine in an application can greatly enhance the flexibility and scalability of the program, similar to the macro functions of MS Office and VS.NET. In the Microsoft .NET framework, Microsoft.vsa.dll defines the script engine framework, while Microsoft.Visualbase.vsa.dll defines the script engine that implements VBA. You can use these two DLLs to define your own script engine based on VBA.NET.
Microsoft.vsa.dll defines some framework interfaces, among which the more important interfaces include
IVsaEngine is the script engine interface, all script engines use this interface
IVsaSite script engine communication interface, the script engine accepts this interface to publish some information
IVsaItem is an item related to script engine resources
IVsaCodeItem is the script code module
IVsaRefrenceItem is the external reference object used by the script engine
IVsaGlobalItem is a global object module used by script engines.
The usage process is generally to instantiate a script engine, pass the object that implements IVsaSite to the script engine object, and then use the CreateItem method of the engine's Items to add references, code text and global objects. Then call The Compile method compiles the script engine and uses RUN to start the engine.
After the script engine is started, an Assembly assembly is dynamically generated and loaded in the current application domain based on the script code. Use IVsaEngine.Assembly to access the dynamically generated assembly.
Microsoft.VisualBase.vsa.dll implements these interfaces and implements a scripting engine based on VBA.NET syntax.
The main object is VsaEngine.
This program provides a demo program written in C#, using the Microsoft .NET Framework 1.1. The demo program provides a general module for using the script engine. By using this module, you can easily use the VBA script engine to expand. own application.
Demo program download address:
Source: XDesigner BLOG