1. ## Does anybody have any good code on how to determine whether a number is even or odd? I came up with some simplistic code using a For Next loop, but im looking for something better. Thanx a lot.  Reply With Quote

2. ## Use Mod:

-------------
If Number Mod 2 = 0 then ' Number is even
Else ' Number is odd
End If
-------------  Reply With Quote

3. ## This gives you an idea of how to determine whether a number is even or odd.

Code:
```        Dim mlimit As Integer
Dim num As Integer
mlimit = 20

Case EVEN
For num = 0 To mlimit
If num Mod 2 = 0 Then
If num &gt; 0 Then Debug.Print num;
End If
Next num

Case ODD
For num = 0 To mlimit
If num Mod 2 = 1 Then
If num &gt; 0 Then Debug.Print num;
End If
Next num```
Hope this helps.

Ruchi

[This message has been edited by Ruchi (edited 01-08-2000).]  Reply With Quote

4. ## You can also use this function which returns True if the number is even, False if it is odd.

Function IsEven(iEven as Long) as Boolean
IsEven = (iEven mod 2 = 0)
End Function  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•