MicroStation Visual Basic for Applications
|
LA Solutions staff have written a number of technical articles. These include programming, MicroStation®, GIS, and relational databases. Some articles describe aspects of MicroStation software development, and others provide code examples.
You may also find the BE Newsletter useful. It is published by Bentley Systems.
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 64-bit 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.
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.
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.
The
Debug
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 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.
MicroStation CONNECT introduced the DgnPlatformNet, a .NET API. You can write a MicroStation AddIn using the DgnPlatformNet using your preferred .NET language.
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 .mvba
file.
VB.NET cannot read a .mvba
binary file.
If you want to move VBA code to a VB.NET 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.
You will need to modify the code to make it compatible with VB.NET. A better route to using VB.NET would be to make use of the DgnPlatformNet API.