logo WinWrap®

Preparsing Modules with DesignMode

WinWrap® Basic is an embedded macro language component available for .NET and COM 32/64 bit Windows applications. The WinWrap® Basic Component is an alternative to Visual Basic for Applications (VBA), ActiveX (e.g. VBScript, JScript, PerlScript, Rexx-based WSH engines and others), and VSTA for this purpose. The WinWrap® Basic Component is compatible with VBA, Sax Basic, VB.NET and Visual Basic 6.0 style scripts.

Preparsing modules can enhance script execution speed.


Why Preparse Modules

The '#Uses directive loads the modules if the modules are not already loaded. Using MacroRun or running the same macro repeatedly causes the modules to be parsed each time. LoadModule can parse the code and keep it memory, however a module which is loaded into memory can't be edited. The only way to edit the code is to use UnloadModule first.

The Preferred Technique for Managing Preparsed Modules

Preparsing Modules with DesignMode

The benefit of preparsing modules must not interfere with the user's need to edit the modules. The preferred technique for managing preparsed modules is to use Design Mode. Setting DesignModeVisible to True adds the Design Mode menu choice to the Macro menu and the Design Mode tool to the toolbar. Either toggles the DesignMode property. When DesignMode changes from True to False the LeaveDesignMode event is fired and when DesignMode changes from False to True the EnterDesignMode event is fired. This allows the application to determine the exact meanings of DesignMode=True and DesignMode=False. DesignMode starts out as True. Your application can set DesignMode to False during startup if desired.

LeaveDesignMode Event

When the DesignMode property changes from True to False the LeaveDesignMode event is fired. In LeaveDesignMode call LoadModule for a module which has zero or more '#Uses directives. That way any macro which uses any of the modules does not need to read/parse them. The user needs to be able to define the module that LoadModule loads. This event can be cancelled. Typically, any parsing failure should set Cancel to True.
Private Sub BasicIdeCtl1_LeaveDesignMode(ByRef Cancel As Boolean) Cancel = Not BasicIdeCtl1.LoadModule("...") End Sub

EnterDesignMode Event

When the DesignMode property changes from False to True the EnterDesignMode event is fired. In EnterDesignMode call UnloadModule. This event can be cancelled. Typically, if execution can't be stopped set Cancel to True.
Private Sub BasicIdeCtl1_EnterDesignMode(ByRef Cancel As Boolean) BasicIdeCtl1.Run = False Cancel = BasicIdeCtl1.Run OrElse Not BasicIdeCtl1.UnloadModule("...") End Sub

Copyright Polar Engineering, Inc.