Solved

# Check if value is EVEN or ODD

Posted on 2006-05-17
335 Views
Hi,

Is there a way I can check to see if a value is even or odd? Something like

IF var = EVEN Then... etc, etc.

Thanks.
0

LVL 7

Expert Comment

if ( x % 1) = 1 then
' Value is odd
else
' Value is odd
end if
0

LVL 7

Expert Comment

oops - second one is even
0

LVL 7

Assisted Solution

it should actually be % 2 not %1 as well.

if ( x % 2) = 1 then
' Value is odd
else
' Value is even
end if
0

LVL 13

Expert Comment

Ah, the joys of air-code.  Dontcha hate that?  I was just about to tip you off but you caught it first.
0

LVL 13

Accepted Solution

Also, it's not % it's Mod.

If CBool(x Mod 2) Then
'value is odd
Else
'value is even
End If

:)
0

LVL 13

Expert Comment

(You were thinking of SQL Server, where the modulus operator is %)
0

LVL 7

Expert Comment

jmundsack is quite right - I was just killing time whilst waiting for a server install to complete.
0

## Featured Post

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…