Results 1 to 3 of 3

Thread: Newbie code question

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Moose Jaw
    Posts
    4

    Talking

    Hi all,

    How can I make Visual basic tell whether an integer is an odd or even number.

    Thanks,

    Justin Arendt
    MCSE, MCP+I

  2. #2
    Guest
    Try this:

    Code:
    Public Function EvenOdd(num&) As Boolean
        Dim a As Long
        a = (Int(num& / 2)) * 2
        If a = num& Then EvenOdd = True 'Even
        If a <> num& Then EvenOdd = False 'Odd
    End Function
    
    Usage:
    
    If EvenOdd(2) Then
    MsgBox "Even"
    Else
    MsgBox "Odd"
    End If

  3. #3
    Guest

    Wink Dead easy!

    Code:
    Answer = MyNumber Mod 2
    if you run this and answer turns out to be 1 then it is an odd number, if you get 0 instead then it is an even number

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width