Option Explicit
Private Type Cols
r As Long
g As Long
b As Long
End Type
Dim colA As Cols
Dim colB As Cols
Private Sub form_load()
colA = longToRgb(Form1.BackColor)
colB = longToRgb(Text1.BackColor)
If CompareCols(colA, colB) = True Then MsgBox "Colors roughly match" Else MsgBox "colors too far apart to match"
End Sub
Private Function longToRgb(ByVal colLong As Long) As Cols
longToRgb.r = CLng((colLong And &HFF))
longToRgb.g = CLng(((colLong \ &H100&) And &HFF&))
longToRgb.b = CLng(((colLong \ &H10000) And &HFF&))
End Function
Private Function CompareCols(col1 As Cols, col2 As Cols) As Boolean
If col1.r < col2.r + 5 And col1.r > col2.r - 6 Then
If col1.g < col2.g + 5 And col1.g > col2.g - 6 Then
If col1.b < col2.b + 5 And col1.b > col2.b - 6 Then
CompareCols = True ' values are within -5 or +6
End If 'b
End If 'g
End If 'r
End Function