DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: How do you tell if a number is even or odd..

  1. #1
    CS Schmidt Guest

    How do you tell if a number is even or odd..


    is there some function out there somewhere to tell if a number is even or
    odd in VB?

  2. #2
    Mattias Sjögren Guest

    Re: How do you tell if a number is even or odd..


    >is there some function out there somewhere to tell if a number is even or odd in VB?


    Just use the Mod operator.

    If n Mod 2 Then
    Debug.Print "n is odd"
    Else
    Debug.Print "n is even"
    End If


    Mattias

    ____________________________________________
    Mattias Sjögren - mattiass @ hem.passagen.se
    http://hem.spray.se/mattias.sjogren/

  3. #3
    Jonas L. Jensen Guest

    Re: How do you tell if a number is even or odd..

    well....
    you could use:


    Dim x as Integer
    Dim Even as Boolean

    if x Mod 2 = 0 then Even = True else Even = false


    Jonas L. Jensen




  4. #4
    Shelly Rosenfeld Guest

    Re: How do you tell if a number is even or odd..


    Odd = CBool(n mod 2)
    Even = Not Odd

    Sheldon

    CS Schmidt <CSchmidt@pobox.ci.boise.id.us> wrote in message
    news:395913f1$1@news.devx.com...
    >
    > is there some function out there somewhere to tell if a number is even or
    > odd in VB?




  5. #5
    Rick Rothstein Guest

    Re: How do you tell if a number is even or odd..

    Just to be different <g>

    If your Number is in string form (say, from a TextBox), a String variable or
    a Variant variable, then

    Even = Number Like "*[02468]"

    Odd = Number Like "*[13579]"

    Rick


    CS Schmidt <CSchmidt@pobox.ci.boise.id.us> wrote in message
    news:395913f1$1@news.devx.com...
    >
    > is there some function out there somewhere to tell if a number is even or
    > odd in VB?




  6. #6
    Shelly Rosenfeld Guest

    Re: How do you tell if a number is even or odd..


    So like maybe it could be yet more efficient, like oh,
    say, placing those values in a resource file? Oh, yeah!

    Sheldon

    Rick Rothstein <fnroth@aosi.com> wrote in message
    news:395922c7$1@news.devx.com...
    > Just to be different <g>
    >
    > If your Number is in string form (say, from a TextBox), a String variable

    or
    > a Variant variable, then
    >
    > Even = Number Like "*[02468]"
    >
    > Odd = Number Like "*[13579]"
    >
    > Rick





  7. #7
    bob butler Guest

    Re: How do you tell if a number is even or odd..


    Shelly Rosenfeld <ShellyRo@worldnet.att.net> wrote in message
    news:39591804@news.devx.com...
    >
    > Odd = CBool(n mod 2)
    > Even = Not Odd
    >
    > Sheldon
    >
    > CS Schmidt <CSchmidt@pobox.ci.boise.id.us> wrote in message
    > news:395913f1$1@news.devx.com...
    > >
    > > is there some function out there somewhere to tell if a number is even

    or
    > > odd in VB?


    and another variation:

    odd=cbool(n and 1)




  8. #8
    Shelly Rosenfeld Guest

    Re: How do you tell if a number is even or odd..


    You bit-wise guys are killin' me! <g>

    Sheldon

    bob butler <butlerbob@my-Deja.com> wrote in message
    news:395931f2@news.devx.com...

    > > CS Schmidt <CSchmidt@pobox.ci.boise.id.us> wrote in message
    > > news:395913f1$1@news.devx.com...
    > > >
    > > > is there some function out there somewhere to tell if a number is even

    > or
    > > > odd in VB?

    >
    > and another variation:
    >
    > odd=cbool(n and 1)
    >
    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center