|
-
Jan 7th, 2000, 10:25 AM
#1
Thread Starter
New Member
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.
-
Jan 7th, 2000, 10:42 AM
#2
Hyperactive Member
Use Mod:
-------------
If Number Mod 2 = 0 then ' Number is even
Else ' Number is odd
End If
-------------
-
Jan 7th, 2000, 01:50 PM
#3
Member
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 > 0 Then Debug.Print num;
End If
Next num
Case ODD
For num = 0 To mlimit
If num Mod 2 = 1 Then
If num > 0 Then Debug.Print num;
End If
Next num
Hope this helps.
Ruchi
[This message has been edited by Ruchi (edited 01-08-2000).]
-
Jan 9th, 2000, 05:05 PM
#4
Lively Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|