even numbers

M

Mark J. McGinty

polilop said:
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
 
P

polilop

did not know that,
thank you.
Mark J. McGinty said:
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
 
D

Dave Anderson

Mark said:
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.
 
M

Mark J. McGinty

Dave Anderson said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,158
Messages
2,570,882
Members
47,414
Latest member
djangoframe

Latest Threads

Top