469,306 Members | 1,987 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

even numbers

how can i check if a variable is an even number?
Jul 22 '05 #1
4 1686

"polilop" <fm******@inet.hr> wrote in message
news:el**************@TK2MSFTNGP09.phx.gbl...
how can i check if a variable is an even number?


Assuming the variable identifier is 'n':

If (n Mod 2) = 0 Then ...

Mod is the VBS modulus operator, it returns the remainder of a division
operation.
-Mark
Jul 22 '05 #2
did not know that,
thank you.
"Mark J. McGinty" <mm******@spamfromyou.com> wrote in message
news:eI**************@TK2MSFTNGP12.phx.gbl...

"polilop" <fm******@inet.hr> wrote in message
news:el**************@TK2MSFTNGP09.phx.gbl...
how can i check if a variable is an even number?


Assuming the variable identifier is 'n':

If (n Mod 2) = 0 Then ...

Mod is the VBS modulus operator, it returns the remainder of a division
operation.
-Mark

Jul 22 '05 #3
Mark J. McGinty wrote:
If (n Mod 2) = 0 Then ...


Alternatively:
If n/2 = n\2 Then ...

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 22 '05 #4

"Dave Anderson" <GT**********@spammotel.com> wrote in message
news:ew**************@TK2MSFTNGP09.phx.gbl...
Mark J. McGinty wrote:
If (n Mod 2) = 0 Then ...
Alternatively:
If n/2 = n\2 Then ...


But that incurs overhead for an integer division op, plus a floating point
division op, then a comparison of floats (after implicit type promotion of
the integer expression.)

Mod is just one integer division op, (unless n happens to be floating point)
and then integer comparison. Further, Mod will tolerate Empty as the first
operand.

Lastly... well "intuitive" is in the eye of the beholder, so I'll skip the
rest.
-Mark

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use of this email address implies consent to these terms. Please do not
contact me directly or ask me to contact you directly for assistance. If
your question is worth asking, it's worth posting.

Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Debbie Lucier | last post: by
2 posts views Thread by Lance Hoffmeyer | last post: by
6 posts views Thread by devoreband | last post: by
25 posts views Thread by melsayid | last post: by
30 posts views Thread by bdsatish | last post: by
18 posts views Thread by =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.