Is this number a multiple of 20?

Posted on 2006-04-06
Medium Priority
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


            CheckMultiple = False

     End If

End Function

Thanks all!
Question by:butterhook
LVL 43

Expert Comment

ID: 16391827
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
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 200 total points
ID: 16391829
IsThisAMultipleFunction = (WhichNumber % 20 = 0)
LVL 70

Expert Comment

by:Éric Moreau
ID: 16391845
       use the modulo operator:        
if WhichNumber mod 20 = 0 then  
            CheckMultiple = True
            CheckMultiple = False
     End If      
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 44

Expert Comment

ID: 16391864
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)


Author Comment

ID: 16391884
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
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16391929
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)

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question