Providing a Startup Script
A useful customization is to allow an
option for a startup script. The script could be a standard,
hardcoded filename or a configuration variable. Users can do almost
anything with this script; they can put in a series of standard
import statements, go off and import commonly used data files from
elsewhere, and (as we’ll see) set up the
BookSet as they want with validation rules and
custom views. The script executes after the
BookSet has been initialized, so it can’t
control the way BookSet initializes.
This feature is easy to provide with the tools we’ve just built. In Figure 8.3, we’ve gone for a user-defined script name in an Options dialog.
![]() |
Earlier on we put two public methods in frmMain
called
InitCOMServer
and
CloseCOMServer
, and never used the latter. Here
there’s a good use for it. InitCOMServer has
been expanded as follows (ignoring error trapping to save space):
Sub InitCOMServer() Dim startupScript As String 'called when the program starts On Error GoTo InitCOMServer_error Set BookServer = CreateObject("Doubletalk.BookServer") On Error GoTo 0 'tell it to capture output for the console BookServer.beginTrappingOutput 'if there is an init script, run it If frmOptions.txtStartupScript.text <> "" Then On Error GoTo InitCOMServer_StartupScriptError BookServer.execFile frmOptions.txtStartupScript.text ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access
