3 Replies - 8646 Views - Last Post: 30 April 2010 - 10:21 PM Rate Topic: -----

#1 Ewinz87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 25-May 09

How to check if a number is a muliple of

Posted 30 April 2010 - 09:36 PM

I can't seem to figure out how to make a function that check if x is a multiple of y. For example, 64 is a multiple of 8.

Here's what I have, it's simple but I'm stuck:

Function IsMultiple(ByVal Number As Integer, ByVal Multiple As Integer) As Boolean
        If Number / Multiple = 0 Then
            IsMultiple = True
        End If
    End Function


Line2, if the number is a multiple it would return a number without decimal, but I dunno how to check if it is or not.

Is This A Good Question/Topic? 0
  • +

Replies To: How to check if a number is a muliple of

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How to check if a number is a muliple of

Posted 30 April 2010 - 09:50 PM

Use the Modulus Operator (Mod)

Function IsMultiple(ByVal Number As Integer, ByVal Multiple As Integer) As Boolean
    If Number Mod Multiple = 0 Then
        Return True
    End If
    
    Return False
End Function


Was This Post Helpful? 2
  • +
  • -

#3 Ewinz87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 25-May 09

Re: How to check if a number is a muliple of

Posted 30 April 2010 - 10:05 PM

View PostPsychoCoder, on 30 April 2010 - 08:50 PM, said:

Use the Modulus Operator (Mod)

Function IsMultiple(ByVal Number As Integer, ByVal Multiple As Integer) As Boolean
    If Number Mod Multiple = 0 Then
        Return True
    End If
    
    Return False
End Function



Thank you very much, works perfectly. :D
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How to check if a number is a muliple of

Posted 30 April 2010 - 10:21 PM

No problem, glad I could help :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1