|
Programmatic Execution |
|
See Also: |
APG scripts can be run in Visual Basic applications or in Visual Basic COM components. This topic shows how.
To use the APGen COM components in Visual Basic, add a reference to the "Active Page Generator 2.1 Type Library". To do this, choose "Project | References..." in the Visual Basic menu, and check the checkbox next to "Active Page Generator 2.1 Type Library".
After adding the type library reference, the APGen objects can be
browsed in the Object Browser. APGen objects are contained
in the type library APGenLib. The only createable object
is the APGen object.
This code implements a simple VB COM object, which acts as a
wrapper for the APGen object. The VB class, named APGen_Wrapper,
has a read/write property named OutputDir, and a method
named RunScript().
Option Explicit
' Private member variable
Private m_sOutputDir As String
Public Property Get OutputDir() As String
OutputDir = m_sOutputDir
End Property
Public Property Let OutputDir(ByVal sOutputDir As String)
m_sOutputDir = sOutputDir
End Property
Public Sub RunScript(ByVal sPath As String)
' Create an APGen object
Dim oAPGen As APGen
Set oAPGen = New APGen
' Turn off debugging for production code
oAPGen.Debug = False
' Set the output directory
oAPGen.OutputDir = m_sOutputDir
' Open an APG script
Dim oAPGScript As APGScript
Set oAPGScript = oAPGen.OpenScript(sPath)
' Set so errors are written to the Event Log
oAPGScript.Log.Flags = apgEventLogErrors
' Execute the APG script
oAPGScript.Run
End Sub
This APGen_Wrapper COM object can be installed in an MTS or COM+ package, and it can be used as a queued component in COM+.