SARG wrote:Josep Roca wrote:It is ignored since "1" is not a number, but a string.
Ok but how to explain that in the variation by srvaldez : v1 = v1 - "1" gives the right value ?
Because in the operator
-, I call the API function VarSub without checking the type of the passed variants
Code: Select all
' ========================================================================================
PRIVATE OPERATOR - (BYREF cv1 AS CVAR, BYREF cv2 AS CVAR) AS CVAR
' // Subtract
DIM cvRes AS CVAR
VarSub(@cv1.vd, @cv2.vd, cvRes.vptr)
OPERATOR = cvRes
END OPERATOR
' ========================================================================================
[VarSub tries to coerce the type of the variant passed if they are of different type]
whereas I do it in the operator
-=Code: Select all
' ========================================================================================
PRIVATE OPERATOR CVar.-= (BYREF cv AS CVAR)
CVAR_DP("CVAR -=")
IF vd.vt <> VT_BSTR AND cv.vd.vt <> VT_BSTR THEN
DIM vRes AS VARIANT
IF VarSub(@vd, @cv.vd, @vRes) = S_OK THEN VariantCopy(@vd, @vRes)
END IF
END OPERATOR
' ========================================================================================
If I remove the check then it will work.
I never occurred to me to test the implemented operators substracting an string from a number.
Should I remove the checks?