Questions similar to these appear in the Be Communities Programming Forum.
This page lists some solutions to common MicroStation VBA (MVBA) problems. Tips are published as examples and are not necessarily working code.
Each and every element in a a DGN file has a unique Element ID. The ID is a 64-bit integer number. A MicroStation user has little reason to know of the ID, but it's visible in the Element Information dialog …
The Element ID is shown in the Raw Data region near the bottom of that dialog.
VBA for MicroStation CONNECT continues to support the DLong data type so that legacy VBA applications don't break. However, since MicroStation CONNECT is a 64-bit application, so also is VBA. The VBA in MicroStation CONNECT is VBA version 7.1, as implemented by Microsoft in its 64-bit Office applications.
In particular, VBA 7.1 introduces the LongLong
data type, which is a 64-bit integer.
You can use a variable having that data type to store an element ID …
Dim oElement As Element
Set oElement = ... get element from somewhere
Dim id As LongLong
id = oElement.ID64
Debug.Print "Element ID=" & CStr(id)
Using VBA you can obtain an element's Element ID using the Element.ID
method.
The ID is returned in a
DLong user defined type (UDT).
Dim oElement As Element
Set oElement = ... get element from somewhere
Dim id As DLong
id = oElement.ID
Debug.Print "Element ID=" & DLongToString (id)
Bentley Systems developed MicroStation VBA from Microsoft's VBA Toolkit. VBA is an elderly technology, corresponding to Visual Basic (VB) 5½. MicroStation V8 delivers 32-bit VBA technology, which does not comprehend or support 64-bit numbers.
To solve that lack of support for 64-bit numbers in the VBA Toolkit,
Bentley Systems invented the DLong
user defined type (UDT) and a handful of functions
to deal with it.
A DLong
packs two 32-bit numbers into that UDT.
You should not concern yourself with the .Low
and .High
components.
Always treat a DLong
, and hence an Element.ID
, as if it were a single number.
If you search VBA help for DLong
you will find the functions that let you compare
DLong
s, convert a DLong
to a DLong
String, assign a value to a DLong
,
and a few more.
Function | Description |
---|---|
DLongToLong | Converts a DLong to a Long |
DLongFromLong | Converts a Long to a DLong |
DLongToString | Converts a DLong to a String |
DLongFromString | Converts a String to a DLong |
DLongToHexString | Converts a DLong to a String in hexadecimal format |
DLongFromHexString | Converts a String in hexadecimal format to a DLong |
DLongFromDouble | Converts a Double to a DLong |
DLongComp | Compares two DLongs |
DLongAdd | Calculates the sum of two DLongs |
DLongSubtract | Calculates the difference between two DLongss |
DLongMultiply | Calculates the product of two DLongs |
DLongDivide | Calculates the quotient of two DLongs |
DLongMode | Calculates the modulus (remainder after division) |
DLongNegate | Reverses the sign of a DLong |
DLongAbs | Calculates the absolute value of a DLong |
MicroStation V8i VBA requires the DLong
user defined type
because it can't provide 64-bit integers.
When VBA was invented, it had nothing bigger than a 32-bit (Long
) integer .
MicroStation CONNECT delivers 64-bit VBA, which does provide 64-bit (LongLong
) integers.
Visual C++ provides the __int64
data type,
which matches perfectly MDL's mdlElement_getID
function.
The MDL header files provide the typedef
or alias
ElementID
for __int64
.
.NET understands 64-bit integers.
C#, for example, has the Int64
data type.
Post questions about MicroStation programming to the MicroStation Programming Forum.