MicroStation is Bentley Systems flagship 3D computer-aided-design tool. Developers can customise MicroStation using one of several Application Programming Interfaces (APIs). This page lists some solutions to common MicroStation VBA (MVBA) problems. Tips are published as examples and are not necessarily working code.
A good place to post questions about MicroStation VBA is the Bentley Communities MicroStation Programming Forum.
This article, aimed at MicroStation VBA programmers, discusses several topics …
The MicroStation Development Library (MDL) provides C-style functions. It is an implementation of the C language, with an extensive library of functions that use MicroStation's core functionality.
While MicroStation VBA is comprehensive, there are some dark corners of MicroStation that it doesn't reach. To poke around in those dusty nooks, you need MDL.
MicroStation CONNECT is the first 64-bit version of MicroStation. MicroStation CONNECT includes Microsoft VBA version 7.1.
To use MDL functions, you must understand the data types used and their names. VBA 7 is an evolution of Microsoft VBA and is a 64-bit programming tool There are differences you need to know about …
MDL and VBA use Unicode strings, which have 16-bit characters. Previous versions of MicroStation use mostly multibyte (8-bit character) C-style strings with MDL.
MDL and VBA use several integer types. This table summarises the most common …
MDL | VBA | Bits | Comment |
---|---|---|---|
short | Integer | 16 | |
int | Long | 32 | |
long | Long | 32 | |
__int64 | LongLong | 64 | __intNN data types are Microsoft-specific |
Bentley Systems added the DLong user-defined type (UDT) to MicroStation VBA. The DLong data type is retained for compatibility with VBA in previous versions of MicroStation.
Real (floating-point) numbers generally are stored in 64-bit double (MDL) and Double (VBA) variables. double and Double are identical, so there's no need to translate between them.
There's no word in VBA for pointer. VBA doesn't do pointers. In C-style languages, such as MDL and C++, pointers are part of the language and are used frequently.
In MDL for 64-bit versions of MicroStation, a pointer is an unsigned integer of 64 bits. In VBA, a pointer is passed as a LongPtr value. Consider the example mentioned above. Its declaration for VBA 7 is …
Declare PtrSafe Function mdlWindow_toFront Lib "stdmdlbltin.dll" (ByVal windowP As LongPtr) As Long
That function takes as its parameter an MDL window pointer. The pointer is passed as a LongPtr. You need to be aware of pointers, and be prepared to pass them by value between your VBA code and any MDL function you call.
Don't attempt to modify a pointer in VBA. VBA has no idiom for pointer manipulation.
The PtrSafe keyword is required. It declares that a function is usable in a 64-bit world.