butterhook
asked on
Is this number a multiple of 20?
Hello. I know this sounds stupid but what is the function for discrening whether a variable is a multiple of 20?
I.e. how can I get a boolean response for this question?
for example:
Function CheckMultiple(WhichNumber as long) as boolean
if IsThisAMultipleFunction(Wh ichNumber, 20) Then
CheckMultiple = True
Else
CheckMultiple = False
End If
End Function
Thanks all!
I.e. how can I get a boolean response for this question?
for example:
Function CheckMultiple(WhichNumber as long) as boolean
if IsThisAMultipleFunction(Wh
CheckMultiple = True
Else
CheckMultiple = False
End If
End Function
Thanks all!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
use the modulo operator:
if WhichNumber mod 20 = 0 then
CheckMultiple = True
Else
CheckMultiple = False
End If
if WhichNumber mod 20 = 0 then
CheckMultiple = True
Else
CheckMultiple = False
End If
angelIII's answer is 100% correct. It makes use of the Modulus operator, which returns the REMAINDER when the number on the Left is Divided By the number on the Right
12 % 10 = 2 (12 divided by 10 leaves a remainder of 2)
23 % 3 = 2 (23 divided by 3 = 7 with a remainder of 2)
AW
12 % 10 = 2 (12 divided by 10 leaves a remainder of 2)
23 % 3 = 2 (23 divided by 3 = 7 with a remainder of 2)
AW
ASKER
Thanks guys, you are all so incredibly fast off the mark. Sorry I couldn't split the points but I couldn't work out how to divide them! Maybe that will be another question at some point
50 points cannot be divided, as you need to give at least 30 points per comment.
In case you fulfill that, you can see a 'split points' link below the last comment (before the q is closed)
In case you fulfill that, you can see a 'split points' link below the last comment (before the q is closed)
Function CheckMultiple(ByVal Which As Long, Optional ByVal OfWhat As Long = 20) As Boolean
CheckMultiple = (Which Mod OfWhat) = 0
End Function
You can call this either with a single parameter or two if you want to change the divisor.
Tim Cottee