MicroStation Visual Basic for Applications
LA Solutions staff have written a number of technical articles. These include programming, MicroStation®, GeoGraphics™, and relational databases. Some articles describe aspects of MicroStation software development, and others provide code examples.
We've written a miscellany of VBA tips, plus some longer articles listed here. We also answer that common question: "Where is MicroStation VBA Help?"
MVBA is Bentley Systems' adaptation of the Microsoft VBA toolkit. It provides a subset of Visual Basic™ (VB) functionality and is similar to the VBA implementations in Microsoft Word™, Excel™ and applications from third-parties. A MicroStation installation includes a VBA Help file, which provides extensive documentation and example code.
See our books page for information about books that may be interesting to MicroStation developers.
Where MVBA differs from other VBA implementations is its support for MicroStation. Just as VBA for Microsoft Word provides programming models for words and paragraphs, MVBA provides programming models for graphic elements, reference models, keyin commands, and many other features unique to MicroStation.
MVBA uses VB syntax and is easy to learn: there are many books and other tutorials available for Visual Basic beginners. The Interactive Design Environment (IDE) is similar to the IDE in Word and Excel, and not too dissimilar to the IDE in VB itself.
VBA's Interactive Development Environment (IDE) provides a lot of tools to help you. Explore the IDE. Take a VBA training class.
VBA includes debugging tools.
Function key F8 lets you step through your code and examine the state of your variables.
object is your friend.
Debug.Print "Trace message" gives you information that only you can see in the IDE.
See also the MicroStation
Message Center that can provide debug data to your users.
One irritating failing of VBA, and Visual Basic as well, is its lack of support for a mouse wheel. That is, you can't use the wheel on your mouse to scroll through code in the VBA IDE. However, Microsoft has published a fix for this problem. Visit this link to learn how to enable mouse-wheel scrolling in both VB and VBA.
One of the simplest ways to get started with VBA is to record a macro. Use MicroStation menu Utitilities|Project Manager to pop the VBA Project dialog. The record macro buttons let you capture your user actions as a VBA recording.
Q How can I use VBA with .NET?
A A common question that has no simple answer. VBA and .NET are both Microsoft technologies. However, VBA predates .NET by several years. Unfortunately, they don't work together.
It's possible to write functionality using .NET that you can use from VBA. The trick is to write a DLL using your favourite .NET language, and make that DLL COM-compatible. Use Visual Studio .NET to develop a COM server implemented in a DLL. This article shows the tricks and pitfalls.
|Topic||Title||Article Location||Sample Code|
|Administration||Configuration Variables||Configuration Variables and VBA||Configuration Variables and VBA|
|Algebra||Plotting Curves||Plotting Curves with VBA||Harmonograph VBA Project|
|Regression Analysis||Regression Analysis with VBA||Regression Analysis VBA Project|
|Colour Controls||Color Chooser||Microsoft Common Dialog Color Control|
|ColorPicker||Bentley ColorPicker OCX|
|Databases||Databases||Databases and MicroStation|
|Element ID||Element ID and DLong||Element IDs and DLong user defined type|
|Element Manipulation||Create a Cell Element||Place Cell page||CreatePlacement.zip|
|Create a Shape Element||Create Shape page||CreateShape.zip|
|Create Shape from Closed Line-String||Create Shape from Closed Line-String page||CreateShapesFromLineStrings.zip|
|Create Swing Arrows||Create Swing Arrows page||SwingArrow.zip|
|Locate an Element given its ID||Locate Element page||ElementLocator.zip|
|Mark Circle Centre||Add markup to identify the centre of a circle (or ellipse) page||MarkCircleCentre.zip|
|Move an Element||Move Element page||MoveElement.zip|
|Copy an Element from a 3D model to a 2D model||Copy 3D Element to 2D Model article||Contained in article|
|Setting the Snap Mode||Set Snap Mode page|
|Events||Design File Events||Design File Events page||OpenCloseEventHandler.zip||OpenCloseEventHandler.zip|
|Passing Information to ILocateCommandEvents||Communicating with a Locate Class page||MeasureLine.zip||MeasureLine.zip|
|Excel™||MicroStation™ VBA and Excel™||VBA and Excel page|
|Files||File Locations||File Locations page|
|File Relative Paths||Find Relative Path page|
|Function Keys||Load a Function Key menu||Load a Function Key menu page|
|GeoGraphics||Find Maps about a Point||GeoGraphics page|
|Levels||Level Control & Manipulation||Level Control||Source code included|
|Iterating Level Libraries (DGNLIBs)||Level Libraries||Source code included|
|Measurement||Measure Area of Closed Shapes, Grouped Holes & LineStrings||Measure Area page||Contained in article and MeasureArea.mvba module|
|Are two elements identical?||VBA wrapper around MDL function to compare elements||Code included in article|
|Determine whether a Line is Straight||Is Line Colinear? page||Colinear code included in article|
|Measure the Area of multiple Shape Elements||ShapeTagger||Contained in article ZIP archive|
|Measure the Length of a MultiLine||Measure Lines page||Contained in article|
|Measure the Distance Between Parallel Lines||Measure Lines page||Contained in article|
|Computing Intersections||PDF Document||ComputingIntersections.zip|
|Miscellaneous||Navigating the TCB||Navigating the TCB page. (Also Navigating the TCB with BASIC)|
|Clipboard: Cut and Paste with VBA||Using the Windows Clipboard||Source code included|
|Arithmetic: truncation & rounding with VBA||Numeric Formatting|
|Is an MDL Application Loaded?||Is MDL Loaded page||Source code included|
|Is an element a Grouped Hole?||Grouped Hole Page||Source code included|
|MicroStation VBA Tips||MVBA Tips page||Contained in article|
|Referencing the MicroStation VBA Object Library elsewhere; referencing other libraries in MicroStation VBA||Referencing VBA Object Libraries||Included in article|
|Using MicroStation's Message Center||Message Center page||Contained in article|
|Starting a Batch File||PDF Document||ShellBatch.zip|
|Validating Configuration Variables||Configuration Validator|
|Verifying a DGN File||Check Design File page||Sample code that shows how to check if a file is a DGN file|
|Printing||Printing with VBA||Printing with VBA||Sample code that shows how to control printing using VBA|
|References||Log Reference Attachments||PDF Document||LogRefs.zip|
|Reference Attachment Operations||Reference Attachment Operations page||Attach a reference; set a reference clip boundary|
|Attaching All References||Load Hidden References page||Attach all references — including those that are turned off|
|Rotation: Angles, Radians and Matrices||All about radians, degrees and Matrix3d||Rotation||Sample code that shows how to convert between degrees and radians and how to interpret a rotation matrix|
|Scanning||Searching through a Model for specified elements||Scanning a Model||Included in article|
|Searching through a Model for named cells||Scanning a Model for named cells||FindCell.zip|
|Searching through a Model for lines of a certain size||Scanning a Model for lines of a certain size||FilterLines.zip|
|Enumerating Models or Cells
|| Enumerating Models page
||How to examine the models in a DGN file (a model is a cell; a cell is a model)
|Tags||Reading and Writing Tag Data||Tag Data Overview||Included in article|
|Writing Tag data into a Text File||PDF Document||TextFileReader.zip|
|Text||Text Element Analysis & Manipulation||Text Element page|
|Regular Expressions for MicroStation VBA Developers||Regular Expression page|
|Incrementing Numeric Text||Incrementing a Numeric Text Element||Example VBA code and project available|
|Performing Arithmetic on Numeric Text||Computing the Sum of Numbers in Text Elements||Example VBA code and project available|
|Reading a Text File into Coordinates||PDF Document||TextFileReader.zip|
|Analysing Text Enter Data||Text Enter Data page|
|Text Styles||Text Styles page|
|Undo Grouping||Group Operations in an Undo Group||Undo Grouping page|
|Views||MicroStation View Capture||Capture View page||CaptureView.zip|
|View Settings and Control||View Settings and Control page|
|Windows||Cursor Icon||Assign a Cursor||Example VB and VBA code available|
|File & Folder Browsing||Files and Folders||Example VB and VBA code available|
|Mouse Pointer||Assign a Mouse Pointer in MicroStation|
|Open an Office Document||Open a Word™, Excel™ or other document in MicroStation|
|Run a Batch File||Run a Windows batch (*.bat) file from MicroStation||ShellBatch.zip|
|UNC and Drive Paths||Compare a UNC path with a Drive path using VB or VBA||ComparePaths.zip|
|MicroStation Title||Set MicroStation Title article||SetMicroStationTitle.zip|
|Progress Bar||Progress Bar article||ProgressBarExample.zip|
|Windows Common Dialogs||Common Dialogs page||Contained in article|
|Win32 Window Handle||Window Handle page||Contained in article|
Microsoft provides Visual Basic for Applications to software vendors in its VBA Toolkit.
The vendor uses the VBA Toolkit to implement and customise VBA for their application.
VBA generates binary code that is tightly coupled to the host application.
The code is in a container whose nature depends on the vendor's policy.
For example, a Microsoft Excel™ VBA project is stored in an Excel workbook or add-in.
A MicroStation VBA project is stored in a
Visual Basic cannot read a
.mvba binary file.
If you want to move VBA code to a VB project, then you should export the source code from the VBA project.
Export code from the VBA Interactive Development Environment (IDE) by
right-clicking in the Project window and choose the Export option from the pop-up menu.