String to MicroStation Master Unit Conversion

MicroStation allows users to input units as Sub Units by preceding the value with either a colon, “:6”, or two dots, “..6”. Users may also enter unit values in MU:SU:PU format. In MicroStation dialogs these input formats are automatically converted to their Master Unit equivalents. Unfortunately when writing your own VBA macros in MicroStation there is no automatic conversion. It is up to the macro developer to do this conversion. The StringToMasterUnits function below can be used to test an input string value and convert the various input formats to master units.

Public Function StringToMasterUnits(ByRef strIn As String, ByRef dOut As Double) As Boolean
Dim strSplit() As String
Dim dMU As Double
Dim dSU As Double
Dim dPU As Double
Dim i As Long
Dim iStart As Long
Dim iEnd As Long


StringToMasterUnits = False

If Len(strIn) = 0 Then
' exit if input string is empty
Exit Function
ElseIf Left$(strIn, 2) = ".." Then
' replace initial .. with : for consistent string parsing
strIn = ":" & Mid$(strIn, 3)
End If

dMU = 0
dSU = 0
dPU = 0

strSplit = Split(strIn, ":")
iStart = LBound(strSplit)
iEnd = UBound(strSplit)

For i = iStart To iEnd
If Len(strSplit(i)) > 0 Then
If IsNumeric(strSplit(i)) Then
Select Case i
Case iStart
dMU = CDbl(strSplit(i))
Case iStart + 1
dSU = CDbl(strSplit(i)) / ActiveModelReference.SubUnitsPerMasterUnit
Case iStart + 2
dPU = CDbl(strSplit(i)) / ActiveModelReference.UORsPerMasterUnit
Case Else
Exit For
End Select
Exit Function
End If
End If

dOut = dMU + dSU + dPU
strIn = CStr(dOut)

StringToMasterUnits = True
Exit Function

MsgBox "ERROR: " & CStr(Err.Number) & " - " & Err.Description, vbExclamation, "StringToMasterUnits"
StringToMasterUnits = False
End Function


Since 1996, EnvisionCAD has been a nationally recognized leader in the configuration, customization, implementation, training & support for CAD software solutions. Our individualized approach has benefited private engineering firms and government agencies alike. Basic or advanced, we can help you get the most from your CAD technology.


Leave a Reply

Your email address will not be published. Required fields are marked *