📄 morphlcd.ctl
字号:
'*************************************************************************
'* displays the value stored in the .Value property. The 'ForceDisplay' *
'* parameter is used to force a redisplay when a property is changed. *
'*************************************************************************
Dim sMainValue As String ' non-exponential, main value.
Dim sExponentValue As String ' up to n_NumDigitsExp long exponent (including sign).
Dim IsBase10 As Boolean ' not using this function return value now.
' just in case, so exponent "E" and hex digits get processed correctly.
sValue = UCase(sValue)
' a catch for if there isn't a 0 in front of the decimal separator in a
' fractional value. (That won't happen if control is used correctly.)
If Left(sValue, 1) = "." Then
sValue = "0" & sValue
End If
' determine the color brush to use when displaying the value.
If Val(sValue) < 0 Then
' value is negative; use negative value color brushes.
CurrentLitColorBrush = LCDLitColorBrushNeg
CurrentBurnInColorBrush = LCDBurnInColorBrushNeg
' a word about the PreviousNegative stuff... Normally individual display digits are drawn
' only if the digit has changed from the previous displayed digit in the same position.
' This saves a great deal of time in my timing tests. However, when the sign is changed
' when a new value is displayed, we have to force a redraw of every digit, even if they're
' the same as in previous display. That way a displayed value can't be a mishmash of
' positive and negative value colors.
If Not PreviousNegative Then
PreviousMainValue = String(m_NumDigits, "X")
PreviousExponentValue = String(m_NumDigitsExp, "X")
End If
PreviousNegative = True
Else
' value is positive; use regular (positive number) color brushes.
CurrentLitColorBrush = LCDLitColorBrush
CurrentBurnInColorBrush = LCDBurnInColorBrush
If PreviousNegative Then
PreviousMainValue = String(m_NumDigits, "X")
PreviousExponentValue = String(m_NumDigitsExp, "X")
End If
PreviousNegative = False
End If
' separate possible exponent from overall value.
IsBase10 = SeparateMainValueAndExponent(sValue, sMainValue, sExponentValue)
' display the main value, and also the exponent if permitted by the ShowExponent property.
DisplayMainValue sMainValue, ForceDisplay
If m_ShowExponent Then
DisplayExponentValue sExponentValue, ForceDisplay
End If
End Sub
Private Function SeparateMainValueAndExponent(ByVal sValue As String, ByRef sMainValue As String, ByRef ExponentValue As String) As Boolean
'*************************************************************************
'* if it's an exponential base-10 number, separates the exponent and the *
'* main value. Otherwise returns the value and spaces for exponent. *
'*************************************************************************
Dim ExpPos As Long ' position in value of exponent symbols E+ or E-.
Dim ExponentSign As String ' what sign the exponent is (+ or -).
If InStr(sValue, "E+") > 0 Or InStr(sValue, "E-") > 0 Then
' since we see an "E" followed by a "+" or "-" we know it's the base-10
' exponent "E", not hex "E". Separate the main value and exponent.
ExpPos = InStr(sValue, "E+")
If ExpPos = 0 Then
ExpPos = InStr(sValue, "E-")
End If
sMainValue = Left(sValue, ExpPos - 1)
ExponentSign = Mid(sValue, ExpPos + 1, 1)
ExponentValue = Right(sValue, Len(sValue) - ExpPos - 1)
' grab appropriate part of exponent depending on whether
' we're displaying calculation result exponent or seconds.
If InStr(sValue, ":") = 0 Then
ExponentValue = Right(String(m_NumDigitsExp - 1, "0") & ExponentValue, m_NumDigitsExp - 1)
Else
ExponentValue = Right(String(m_NumDigitsExp - 1, "0") & ExponentValue, m_NumDigitsExp)
End If
If ExponentSign = "-" Then
ExponentValue = ExponentSign & ExponentValue
Else
ExponentValue = " " & ExponentValue
End If
SeparateMainValueAndExponent = True
Else
' could be hex, or a non-exponential decimal value. Just return the original value.
sMainValue = sValue
ExponentValue = String(m_NumDigitsExp, " ")
End If
End Function
Private Sub DisplayMainValue(strValue As String, ByVal ForceDisplay As Boolean)
'*************************************************************************
'* displays non-exponent portion of value stored in .Value property. *
'*************************************************************************
Dim s As String ' right-justified version of value.
Dim i As Long ' loop variable.
Dim CurrentDigit As String ' the current digit being displayed.
ExponentFlag = False
s = strValue
' determine thousands separator placement, if they are to be displayed.
If m_ShowThousandsSeparator Then
DetermineThousandsSeparatorPlacement s
DisplayThousandsSeparators
End If
' erase old decimal separator if displayed; display new one if necessary.
ProcessDecimalSeparator s
' erase old colon if displayed; display new one if necessary.
ProcessColon s
' pad the value with leading spaces.
s = Right(Space(m_NumDigits) & s, m_NumDigits)
' display the main value. Only draw a digit if the particular digit being
' drawn is different from digit the previous time value was displayed.
Select Case m_SegmentStyle
Case [Hexagonal]
For i = 1 To m_NumDigits
CurrentDigit = Mid(s, i, 1)
If (CurrentDigit <> Mid(PreviousMainValue, i, 1)) Or ForceDisplay Then
DisplayHexagonalSegmentDigit CurrentDigit, LCDSegment(), _
DigitXPos(i - 1), m_YOffset, _
m_SegmentHeight, m_SegmentWidth, _
m_InterSegmentGap, DigitWidth, DigitHeight
End If
Next i
Case [Trapezoidal]
For i = 1 To m_NumDigits
CurrentDigit = Mid(s, i, 1)
If (CurrentDigit <> Mid(PreviousMainValue, i, 1)) Or ForceDisplay Then
DisplayTrapezoidalSegmentDigit CurrentDigit, LCDSegment(), _
DigitXPos(i - 1), m_YOffset, _
m_SegmentHeight, m_SegmentWidth, _
m_InterSegmentGap, DigitWidth, DigitHeight
End If
Next i
Case [Rectangular]
For i = 1 To m_NumDigits
CurrentDigit = Mid(s, i, 1)
If (CurrentDigit <> Mid(PreviousMainValue, i, 1)) Or ForceDisplay Then
DisplayRectangularSegmentDigit CurrentDigit, LCDSegment(), _
DigitXPos(i - 1), m_YOffset, _
m_SegmentHeight, m_SegmentWidth, _
m_InterSegmentGap, DigitWidth, DigitHeight
End If
Next i
End Select
UserControl.Refresh
' save the displayed value so we know which LCD digits
' to update the next time we need to display a value.
PreviousMainValue = s
End Sub
Private Sub DisplayExponentValue(strValue As String, ByVal ForceDisplay As Boolean)
'*************************************************************************
'* displays exponent portion of value stored in .Value property. *
'*************************************************************************
Dim s As String ' right-justified version of exponent.
Dim i As Long ' loop variable.
Dim CurrentDigit As String ' the current digit we're displaying.
ExponentFlag = True
s = Right(Space(m_NumDigitsExp) & strValue, m_NumDigitsExp)
' display the exponent. Only draw a digit if the particular digit being
' drawn is different from digit the previous time value was displayed.
Select Case m_SegmentStyleExp
Case [Hexagonal]
For i = 1 To m_NumDigitsExp
CurrentDigit = Mid(s, i, 1)
If (CurrentDigit <> Mid(PreviousExponentValue, i, 1)) Or ForceDisplay Then
DisplayHexagonalSegmentDigit CurrentDigit, LCDSegmentExp(), _
DigitXPosExp(i - 1), m_YOffsetExp, _
m_SegmentHeightExp, m_SegmentWidthExp, _
m_InterSegmentGapExp, DigitWidthExp, DigitHeightExp
End If
Next i
Case [Trapezoidal]
For i = 1 To m_NumDigitsExp
CurrentDigit = Mid(s, i, 1)
If (CurrentDigit <> Mid(PreviousExponentValue, i, 1)) Or ForceDisplay Then
DisplayTrapezoidalSegmentDigit CurrentDigit, LCDSegmentExp(), _
DigitXPosExp(i - 1), m_YOffsetExp, _
m_SegmentHeightExp, m_SegmentWidthExp, _
m_InterSegmentGapExp, DigitWidthExp, DigitHeightExp
End If
Next i
Case [Rectangular]
For i = 1 To m_NumDigitsExp
CurrentDigit = Mid(s, i, 1)
If (CurrentDigit <> Mid(PreviousExponentValue, i, 1)) Or ForceDisplay Then
DisplayRectangularSegmentDigit CurrentDigit, LCDSegmentExp(), _
DigitXPosExp(i - 1), m_YOffsetExp, _
m_SegmentHeightExp, m_SegmentWidthExp, _
m_InterSegmentGapExp, DigitWidthExp, DigitHeightExp
End If
Next i
End Select
UserControl.Refresh
' save the displayed value so we know which LCD digits
' to update the next time we need to display a value.
PreviousExponentValue = s
End Sub
Private Sub DetermineThousandsSeparatorPlacement(ByVal sVal As String)
'*************************************************************************
'* determines which digits in the main value get a thousands separator *
'* afterwards. ThousandsFlag() elements that correspond to LCD digits *
'* that need to be followed by a thousands separator are set to True. *
'* Thanks to Redbird77 for optimizing this routine. *
'*************************************************************************
Dim i As Long ' loop variable.
Dim p1 As Long ' position of first non-zero/minus sign digit.
Dim p2 As Long ' position of decimal separator.
Dim sTmp As String ' padded value.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -