Enum:
Public Enum ComparisonOperator
NotEqualTo = 0
LessThan = 1
LessThanOrEqualTo = 2
EqualTo = 3
GreaterThanOrEqualTo = 4
GreaterThan = 5
End Enum
Code:
Option Explicit
Private pOperator As ComparisonOperator
Private pRightValue As Variant
Private Const NULL_ERROR_TEXT As String = "Invalid Compare input. Cannot compare against Null"
Private Const OBJECT_ERROR_TEXT As String = "Invalid compare input. Input must be a value, not an object"
Public Property Let Operator(ByVal inputOperator As ComparisonOperator)
pOperator = inputOperator
End Property
Public Property Let RightValue(ByVal inputValue As Variant)
If IsNull(inputValue) Then
PrintErrorMessage "Invalid Compare input. Cannot compare against Null"NULL_ERROR_TEXT
Stop
End If
IfElseIf IsObject(inputValue) Then
PrintErrorMessage "Invalid compare input. Input must be a value, not an object"OBJECT_ERROR_TEXT
Stop
End If
pRightValue = inputValue
End Property
Public Function Compare(ByVal leftValue As Variant) As Boolean
If IsNull(leftValueinputValue) Then
PrintErrorMessage "Invalid Compare input. Cannot compare Null"NULL_ERROR_TEXT
Stop
End If
IfElseIf IsObject(leftValueinputValue) Then
PrintErrorMessage "Invalid compare input. Input must be a value, not an object"OBJECT_ERROR_TEXT
Stop
End If
Dim isTrue As Boolean
Select Case pOperator
Case NotEqualTo
isTrue = (leftValue <> pRightValue)
Case LessThan
isTrue = (leftValue < pRightValue)
Case LessThanOrEqualTo
isTrue = (leftValue <= pRightValue)
Case EqualTo
isTrue = (leftValue = pRightValue)
Case GreaterThanOrEqualTo
isTrue = (leftValue >= pRightValue)
Case GreaterThan
isTrue = (leftValue > pRightValue)
Case Else
'/ TODO: Error Handling
Stop
End Select
Compare = isTrue
End Function