Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
| Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 14th, 2003, 11:20 AM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Test if variable is even or odd number

Hi all
 I'm trying to find an easy way to test if a variable is an even or
odd number.

Dim Count as Integer
Count = 0
Do
  Count = Count + 1
  If Count is even then
     perform function
  End if
Loop until count = 100


Thanks for the help
  #2 (permalink)  
Old June 14th, 2003, 12:01 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: High Wycombe, UK, United Kingdom.
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

Check out the MOD operator, this will tell you what the remainder is of a operaton so :

if ((x mod 2)=0) then
    x is even
else
    x is odd
end if
  #3 (permalink)  
Old June 13th, 2016, 08:17 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2016
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Smile checkou!

this is easiest

Private Sub Command1_Click()
If InputBox("") Mod 2 > 0 Then
MsgBox "Odd Number"
Else
MsgBox "Even Number"
End If
End Sub


Similar Threads
Thread Thread Starter Forum Replies Last Post
Load VARIABLE Number of columns cosmokramer Oracle 1 November 2nd, 2008 05:51 PM
SELECT VARIABLE Number of columns drani Oracle 4 September 21st, 2008 01:12 AM
Problem with variable in test condition bartnowa XSLT 3 December 20th, 2007 07:31 AM
Number of table rows to a variable Paula222 Access VBA 2 February 7th, 2006 09:33 AM
variable number of fields in record manisha.anand Oracle 0 July 1st, 2004 05:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.