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.
MicroStation CONNECT (v10) delivers VBA version 7.1. VBA 7.1 is Microsoft's 64-bit version of Visual Basic, and is compatible with VBA 7.1 delivered with Microsoft's Office products.
This article from Stack Overflow discusses the differences between VBA 6.4 and VBA 7.1.
This article from the Microsoft Developer Network (MSDN) discusses the VBA 7 Code Base.
MicroStation V8 (from V8.0 to V8i) delivers VBA version 6.4. VBA 6.4 is Microsoft's 32-bit version of Visual Basic, and is compatible with VBA 6.4 delivered with Microsoft's 32-bit Office products.
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.
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.