|
Theoretically, you can't overload operators in VB. However, in fact, that rule is easy to break(to a degree) with the assistance of these factors:
With this in mind, check this out:
Private mvarValue As String 'local copy
Public Property Let Value(ByVal vData As Variant)
Dim i As Integer, j As Integer, x As Integer, l As Integer
Dim exitflag As Boolean
If VarType(vData) = vbString Then
If InStr(vData, " ") Then
i = 1
j = 1
i = InStr(1, vData, " ")
Do While InStr(i, vData, " ")
j = i
i = InStr(j + 1, vData, " ")
If i = 0 Then i = (Len(vData) - i) + 1: exitflag = True
x = CInt(Mid$(vData, j + 1, i - (j + 1)))
l = x + l
If exitflag Then Exit Do
Loop
mvarValue = " " + CStr(l)
Else
mvarValue = " " + CStr(vData)
End If
ElseIf VarType(vData) = vbDecimal Then
mvarValue = " " + CStr(vData)
End If
End Property
Public Property Get Value() As Variant
Value = mvarValue
End Property
Before you do anything with this class, you must follow these steps:
At this point, you might be a bit confused. Basically, what I've done
is made the property value default. So when you say Next, I've made Finally, I've made the Property Get for value pad it with a space. As a result, you have faked operator overloading. Admitedly, this is not the most useful ability - it is, however, a rather strange artifact.
|