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.

Specifying a startup script from the client
Figure 8.3. Specifying a startup script from the client

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 ...

Get Python Programming On Win32 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.