[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

Check if value is EVEN or ODD

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
eadam-uk
Asked:
eadam-uk
  • 4
  • 3
2 Solutions
 
wesbirdCommented:
if ( x % 1) = 1 then
    ' Value is odd
else
    ' Value is odd
end if
0
 
wesbirdCommented:
oops - second one is even
0
 
wesbirdCommented:
it should actually be % 2 not %1 as well.  

if ( x % 2) = 1 then
    ' Value is odd
else
    ' Value is even
end if
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jmundsackCommented:
Ah, the joys of air-code.  Dontcha hate that?  I was just about to tip you off but you caught it first.
0
 
jmundsackCommented:
Also, it's not % it's Mod.

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

:)
0
 
jmundsackCommented:
(You were thinking of SQL Server, where the modulus operator is %)
0
 
wesbirdCommented:
jmundsack is quite right - I was just killing time whilst waiting for a server install to complete.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now