Link to home
Start Free TrialLog in
Avatar of butterhook
butterhookFlag for United Kingdom of Great Britain and Northern Ireland

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(WhichNumber, 20) Then

            CheckMultiple = True

      Else

            CheckMultiple = False

     End If

End Function

Thanks all!
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi butterhook,

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
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
       use the modulo operator:        
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
Avatar of butterhook

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)