Reputation: 23283
I have a number, say 1535.25
stored as variable possibleDup
, that I'm trying to compare to another number, say 1535
that is the variable realNumber
. Both of these will be the same number, only one is going to be rounded/truncated (realNumber
tends to be truncated, so I can't do a straight numerical comparison).
I'm trying to see if my possibleDup
number is within 1 of the realNumber
. When I do If possibleDup = realNumber Then ...
, it will seldom run, since one tends to have decimals, and the other not.
Normally, I'd do If (realNumber + 1) >= possibleDup >= (realNumber - 1) Then ...
, but you can't set up a logic statement like that in VB (AFAIK).
(Alternative ideas are welcome. I have also tried doing If left(possibleDup,search(".",possibleDup)-1) = realNumber
but my possibleDup
won't always have a decimal, so I'd have to lengthen my code to account for that).
Maybe setting these values as String
instead of Long
and doing a search within the string?
Upvotes: 0
Views: 53
Reputation: 361605
You need to use the And
operator to chain the conditions of your boolean test:
If (realNumber + 1) >= possibleDup And possibleDup >= (realNumber - 1) Then
In this specific case, you could do this:
If Abs(realNumber - possibleDup) <=1 Then
Upvotes: 1