We help IT Professionals succeed at work.

# Is this number a multiple of 20?

on
Medium Priority
189 Views
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!
Comment
Watch Question

## View Solution Only

Commented:
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
Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
IsThisAMultipleFunction = (WhichNumber % 20 = 0)

Not the solution you were looking for? Getting a personalized solution is easy.

Senior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016

Commented:
use the modulo operator:
if WhichNumber mod 20 = 0 then
CheckMultiple = True
Else
CheckMultiple = False
End If

Commented:
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

Commented:
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
Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
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)
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile