We help IT Professionals succeed at work.

Is this number a multiple of 20?

butterhook
butterhook asked
on
Medium Priority
189 Views
Last Modified: 2010-04-07
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

TimCotteeHead of Software Services

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.

Ask the Experts
Éric MoreauSenior .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      
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

Author

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
Guy Hengel [angelIII / a3]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)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

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

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.