String to MicroStation Master Unit Conversion

Published on May 10, 2011

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

Like this article? Share it!

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Privacy Policy