Questions similar to this appear on the MicroStation Programming Forum.
Q You are writing code that may take a long time to execute, and want to provide feedback to your users. You are looking for answers to questions like these …
A A solution to those questions is to pop a modeless UserForm
with a
Progress Bar. Put a Cancel button on there while you're at it, to let your user stop a lengthy task.
Unfortunately there's a catch, but it's one you can work around: VBA 7.1, provided by MicroStation CONNECT, does not provide a Progress Control control. Nor does Microsoft supply a Progress Bar OCX that we can use with 64-bit VBA. However, the MicroStationAPI includes functions that we can borrow in VBA.
This article shows you how to implement a Progress Control in a VBA project by borrowing MicroStationAPI functions. We implement a Progress Bar class in VBA that encapsulates the MicroStationAPI. The macro that you can download shows you how to use that Progress Bar class.
Note 1: VBA for MicroStation V8 6.5 can use Microsoft's 32-bit Progress Control. Unfortunately Microsoft does not provide an equivalent for VBA 7.1.
Note 2: There are several synonyms for Progress Bar, including …
In this project we show you how to use the MicroStationAPI
mdlDialog_completionBar
family of functions.
The MicroStationAPI, including those functions, is delivered when you install the
MicroStation Software Development Kit (SDK).
The SDK is not delivered with MicroStation,
whereas VBA is installed when you install MicroStation.
If you're not interested in an explanation of the code, you can download the VBA project. The project is freeware and includes the source code.
There are three parts to this VBA macro …
clsProgressBar
wraps the MicroStationAPI functions and provides a simple VBA interface
modMain
that provides some utility functions and the Main()
entry point
frmProgressDemo
that displays a user interface and the command buttons to start a lengthy task
Here's the UserForm …
Press the Start button in the Progress Bar in Dialog pane to see a floating progress bar …
Press the Start button in the Progress Bar in Command Windows pane to see a progress bar contained in MicroStation's command status window. This progress bar is thin and there is limited space for a caption …
The clsProgressBar
class presents a simple interface …
OpenFloatingProgressBar (title As String)
displays a progress bar in its own window
OpenStatusPanelProgressBar (title As String)
displays a progress bar in MicroStation's command status area
CloseProgressBar ()
UpdateProgressBar (message As String, percent As Long)
If you examine the source code of that class, you will see a lot of constant definitions filched from the C++ header files.
There are a half-dozen function declarations, which tell VBA where to find mdlDialog_completionBarOpen
and its companions.
Most VBA programmers should leave that class alone!
A sample project is available. It includes code similar to that above and the progress form.
You can download a ZIP file, and then extract ProgressBar.mvba
to a folder
that MicroStation can find. A good place to put it would be
..\Workspace\Standards\macros
, or any other folder specified
in the MS_VBASEARCHDIRECTORIES
configuration variable.
Start the macro with this MicroStation key-in …
vba run [ProgressBar]modMain.Main
Post questions about MicroStation programming to the MicroStation Programming Forum.