By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,167 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,167 IT Pros & Developers. It's quick & easy.

How to determine if a number is odd or even?

P: n/a
Ron
Hello, I want to write some code to determine if a number entered in
a textbox txtnumber is odd or even. How do I do this?

Then if even I want to add 3 to that number and multiply by 4
Or if odd I want to add 2 to that number and multiply by 5

thanks for any help.

Jan 29 '07 #1
Share this Question
Share on Google+
19 Replies


P: n/a
Use the MOD function:

dim Num as integer
if cint(textbox1.text) MOD 2 = 0 then
Num = (cint(textbox1.text) + 3) * 4
else Num = (cint(textbox1.text) + 2) * 5
endif

On Jan 29, 4:04 pm, "Ron" <pts4...@yahoo.comwrote:
Hello, I want to write some code to determine if a number entered in
a textbox txtnumber is odd or even. How do I do this?

Then if even I want to add 3 to that number and multiply by 4
Or if odd I want to add 2 to that number and multiply by 5

thanks for any help.
Jan 29 '07 #2

P: n/a
Ron
yea that worked great,

so If I want to keep doing something ubntil the result is 1 and adding
it to a listbox would I do this?
......
num = txtnumber.text
while num <>1

num = (1 + 0 ) / 1
lsttresult.items.add (num)
' AND I want to keep doing the above and adding it to that lisbox
until num = 1
Is that how I would do it?

On Jan 29, 5:11 pm, ge0193...@otc.edu wrote:
Use the MOD function:

dim Num as integer
if cint(textbox1.text) MOD 2 = 0 then
Num = (cint(textbox1.text) + 3) * 4
else Num = (cint(textbox1.text) + 2) * 5
endif

On Jan 29, 4:04 pm, "Ron" <pts4...@yahoo.comwrote:
Hello, I want to write some code to determine if a number entered in
a textbox txtnumber is odd or even. How do I do this?
Then if even I want to add 3 to that number and multiply by 4
Or if odd I want to add 2 to that number and multiply by 5
thanks for any help.- Hide quoted text -- Show quoted text -
Jan 29 '07 #3

P: n/a


On Jan 29, 5:35 pm, "Ron" <pts4...@yahoo.comwrote:
yea that worked great,

so If I want to keep doing something ubntil the result is 1 and adding
it to a listbox would I do this?
.....
num = txtnumber.text
while num <>1

num = (1 + 0 ) / 1
lsttresult.items.add (num)
' AND I want to keep doing the above and adding it to that lisbox
until num = 1
Is that how I would do it?
Oh dear that's confusing... your loop condition states that the loop
will run as long as num is not equal to 1. Then you go and set num to
1 on the very next line.

Jan 29 '07 #4

P: n/a
Ron
hmm your right, so how do you think I can make this work, I want the
loop to keep going until num is 1 but I also want to keep calculating
num and adding its result to the listbox until it is 1
On Jan 29, 5:53 pm, lord.zol...@gmail.com wrote:
On Jan 29, 5:35 pm, "Ron" <pts4...@yahoo.comwrote:
yea that worked great,
so If I want to keep doing something ubntil the result is 1 and adding
it to a listbox would I do this?
.....
num = txtnumber.text
while num <>1
num = (1 + 0 ) / 1
lsttresult.items.add (num)
' AND I want to keep doing the above and adding it to that lisbox
until num = 1
Is that how I would do it?Oh dear that's confusing... your loop condition states that the loop
will run as long as num is not equal to 1. Then you go and set num to
1 on the very next line.
Jan 30 '07 #5

P: n/a
>Hello, I want to write some code to determine if a number entered in
a textbox txtnumber is odd or even. How do I do this?

Then if even I want to add 3 to that number and multiply by 4
Or if odd I want to add 2 to that number and multiply by 5

Homework?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jan 30 '07 #6

P: n/a
Probably. It's the third time it's come up in the dotnet newsgroups in the
past week. It's like an epidemic. ;-)

Robin S.
-----------------------------------------
"Mattias Sjögren" <ma********************@mvps.orgwrote in message
news:ub****************@TK2MSFTNGP05.phx.gbl...
>
>>Hello, I want to write some code to determine if a number entered in
a textbox txtnumber is odd or even. How do I do this?

Then if even I want to add 3 to that number and multiply by 4
Or if odd I want to add 2 to that number and multiply by 5


Homework?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Jan 30 '07 #7

P: n/a
You know, colleges should really add a course titled "Looking at the
Documentation 101" or even "Searching Google 101." Maybe then these
guys would quit asking us homework questions...

Thanks,

Seth Rowe
On Jan 30, 2:02 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
Probably. It's the third time it's come up in the dotnet newsgroups in the
past week. It's like an epidemic. ;-)

Robin S.
-----------------------------------------"Mattias Sjögren" <mattias.dont.want.s...@mvps.orgwrote in messagenews:ub****************@TK2MSFTNGP05.phx.gb l...
>Hello, I want to write some code to determine if a number entered in
a textbox txtnumber is odd or even. How do I do this?
>Then if even I want to add 3 to that number and multiply by 4
Or if odd I want to add 2 to that number and multiply by 5
Homework?
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jan 30 '07 #8

P: n/a


On Jan 30, 6:54 am, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
You know, colleges should really add a course titled "Looking at the
Documentation 101" or even "Searching Google 101." Maybe then these
guys would quit asking us homework questions...

Thanks,

Seth Rowe
....or "disguising homework assignments as real-world problems". ;) :P

Jan 30 '07 #9

P: n/a
I agree about the documentation but when unfortunately for some of us
Google did not exsits. You guys do not know how good you have it

I remember back when I was a kid I had to walk to school ... in the
snow ... ten miles .... up hill .... both ways .........

On 30 Jan 2007 03:54:02 -0800, "rowe_newsgroups"
<ro********@yahoo.comwrote:
>You know, colleges should really add a course titled "Looking at the
Documentation 101" or even "Searching Google 101." Maybe then these
guys would quit asking us homework questions...

Thanks,

Seth Rowe
On Jan 30, 2:02 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
>Probably. It's the third time it's come up in the dotnet newsgroups in the
past week. It's like an epidemic. ;-)

Robin S.
-----------------------------------------"Mattias Sjögren" <mattias.dont.want.s...@mvps.orgwrote in messagenews:ub****************@TK2MSFTNGP05.phx.gb l...
>>Hello, I want to write some code to determine if a number entered in
a textbox txtnumber is odd or even. How do I do this?
>>Then if even I want to add 3 to that number and multiply by 4
Or if odd I want to add 2 to that number and multiply by 5
Homework?
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jan 30 '07 #10

P: n/a


On Jan 30, 12:57 pm, SomeGrayHa...@gmail.com wrote:
I agree about the documentation but when unfortunately for some of us
Google did not exsits. You guys do not know how good you have it

I remember back when I was a kid I had to walk to school ... in the
snow ... ten miles .... up hill .... both ways .........
You're lucky you had snow! When *I* was young, we only had ice falling
out of the sky (snow had not yet been invented), and the ice pellets
were the size of grapefruits!

Jan 30 '07 #11

P: n/a
They will quit asking when we stop helpign the Indians (natives of
India) learn.
They have a different mentality. If you know it, you should help
them.

FORGET IT.

Enough of our jobs are going there as it is.

As for those non-Indians, they are just too lazy to find it for
themselves.

On Jan 30, 12:23 pm, lord.zol...@gmail.com wrote:
On Jan 30, 12:57 pm, SomeGrayHa...@gmail.com wrote:
I agree about the documentation but when unfortunately for some of us
Google did not exsits. You guys do not know how good you have it
I remember back when I was a kid I had to walk to school ... in the
snow ... ten miles .... up hill .... both ways .........You're lucky you had snow! When *I* was young, we only had ice falling
out of the sky (snow had not yet been invented), and the ice pellets
were the size of grapefruits!
Jan 30 '07 #12

P: n/a
raibeart wrote:
They will quit asking when we stop helpign the Indians (natives of
India) learn.
They have a different mentality. If you know it, you should help
them.

FORGET IT.

Enough of our jobs are going there as it is.

As for those non-Indians, they are just too lazy to find it for
themselves.
Keep in mind that it's not just north-americans that answer questions,
and it's not just non-north-americans the ones who ask then...

Regards,

Branco.

Jan 30 '07 #13

P: n/a
Oh, yeah? *I* used punchcards to write software! Oooooooooooh. (I wonder
if anybody will get that.)

Robin S.
--------------------------------
<lo*********@gmail.comwrote in message
news:11*********************@h3g2000cwc.googlegrou ps.com...
>

On Jan 30, 12:57 pm, SomeGrayHa...@gmail.com wrote:
>I agree about the documentation but when unfortunately for some of us
Google did not exsits. You guys do not know how good you have it

I remember back when I was a kid I had to walk to school ... in the
snow ... ten miles .... up hill .... both ways .........

You're lucky you had snow! When *I* was young, we only had ice falling
out of the sky (snow had not yet been invented), and the ice pellets
were the size of grapefruits!

Jan 31 '07 #14

P: n/a
Well, since we're comparing gray hairs here, of which I have none left to
pull out.....

MY first computer had only four thick wires with 9 circular sliding
components per wire. :)

Bruce

"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:A8******************************@comcast.com. ..
Oh, yeah? *I* used punchcards to write software! Oooooooooooh. (I wonder
if anybody will get that.)

Robin S.
--------------------------------
<lo*********@gmail.comwrote in message
news:11*********************@h3g2000cwc.googlegrou ps.com...
>>

On Jan 30, 12:57 pm, SomeGrayHa...@gmail.com wrote:
>>I agree about the documentation but when unfortunately for some of us
Google did not exsits. You guys do not know how good you have it

I remember back when I was a kid I had to walk to school ... in the
snow ... ten miles .... up hill .... both ways .........

You're lucky you had snow! When *I* was young, we only had ice falling
out of the sky (snow had not yet been invented), and the ice pellets
were the size of grapefruits!


Feb 1 '07 #15

P: n/a
*I* used a slide rule. :-O

Robin S.
-----------------------
"Bruce W. Darby" <kr******@atcomcast.netwrote in message
news:ip******************************@comcast.com. ..
Well, since we're comparing gray hairs here, of which I have none left to
pull out.....

MY first computer had only four thick wires with 9 circular sliding
components per wire. :)

Bruce

"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:A8******************************@comcast.com. ..
>Oh, yeah? *I* used punchcards to write software! Oooooooooooh. (I
wonder if anybody will get that.)

Robin S.
--------------------------------
<lo*********@gmail.comwrote in message
news:11*********************@h3g2000cwc.googlegro ups.com...
>>>

On Jan 30, 12:57 pm, SomeGrayHa...@gmail.com wrote:
I agree about the documentation but when unfortunately for some of us
Google did not exsits. You guys do not know how good you have it

I remember back when I was a kid I had to walk to school ... in the
snow ... ten miles .... up hill .... both ways .........
You're lucky you had snow! When *I* was young, we only had ice falling
out of the sky (snow had not yet been invented), and the ice pellets
were the size of grapefruits!



Feb 1 '07 #16

P: n/a
Not only did I use punch cards, but one time going up to the window to give
my stack of cards to the operator, I dropped the cards! Imagine having to
put them back in the right order? Nightmare!

I wonder if any of the IBM 029 card punch machines still exist?
"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:A8******************************@comcast.com. ..
Oh, yeah? *I* used punchcards to write software! Oooooooooooh. (I wonder
if anybody will get that.)

Robin S.
--------------------------------
<lo*********@gmail.comwrote in message
news:11*********************@h3g2000cwc.googlegrou ps.com...
>>

On Jan 30, 12:57 pm, SomeGrayHa...@gmail.com wrote:
>>I agree about the documentation but when unfortunately for some of us
Google did not exsits. You guys do not know how good you have it

I remember back when I was a kid I had to walk to school ... in the
snow ... ten miles .... up hill .... both ways .........

You're lucky you had snow! When *I* was young, we only had ice falling
out of the sky (snow had not yet been invented), and the ice pellets
were the size of grapefruits!


Feb 1 '07 #17

P: n/a
When I was working at the Army proving grounds in Yuma, AZ, they were
still using one to process payroll.

The poor maintenance contractor had to maintain the beast.

On Feb 1, 12:54 pm, "Zim Babwe"
<zimba...@doyoureallythinkthisisreal.comwrote:
Not only did I use punch cards, but one time going up to the window to give
my stack of cards to the operator, I dropped the cards! Imagine having to
put them back in the right order? Nightmare!

I wonder if any of the IBM 029 card punch machines still exist?

"RobinS" <Rob...@NoSpam.yah.nonewrote in message

news:A8******************************@comcast.com. ..
Oh, yeah? *I* used punchcards to write software! Oooooooooooh. (I wonder
if anybody will get that.)
Robin S.
--------------------------------
<lord.zol...@gmail.comwrote in message
news:11*********************@h3g2000cwc.googlegrou ps.com...
On Jan 30, 12:57 pm, SomeGrayHa...@gmail.com wrote:
I agree about the documentation but when unfortunately for some of us
Google did not exsits. You guys do not know how good you have it
>I remember back when I was a kid I had to walk to school ... in the
snow ... ten miles .... up hill .... both ways .........
You're lucky you had snow! When *I* was young, we only had ice falling
out of the sky (snow had not yet been invented), and the ice pellets
were the size of grapefruits!- Hide quoted text -

- Show quoted text -

Feb 1 '07 #18

P: n/a
Oh, man, I *hate* when that happens!!

Robin S.
---------------------
"Zim Babwe" <zi******@doyoureallythinkthisisreal.comwrote in message
news:OY**************@TK2MSFTNGP03.phx.gbl...
Not only did I use punch cards, but one time going up to the window to
give my stack of cards to the operator, I dropped the cards! Imagine
having to put them back in the right order? Nightmare!

I wonder if any of the IBM 029 card punch machines still exist?
"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:A8******************************@comcast.com. ..
>Oh, yeah? *I* used punchcards to write software! Oooooooooooh. (I
wonder if anybody will get that.)

Robin S.
--------------------------------
<lo*********@gmail.comwrote in message
news:11*********************@h3g2000cwc.googlegro ups.com...
>>>

On Jan 30, 12:57 pm, SomeGrayHa...@gmail.com wrote:
I agree about the documentation but when unfortunately for some of us
Google did not exsits. You guys do not know how good you have it

I remember back when I was a kid I had to walk to school ... in the
snow ... ten miles .... up hill .... both ways .........
You're lucky you had snow! When *I* was young, we only had ice falling
out of the sky (snow had not yet been invented), and the ice pellets
were the size of grapefruits!



Feb 1 '07 #19

P: n/a
How long ago was that?

Robin S.
--------------------------------
"raibeart" <ra******@gmail.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
When I was working at the Army proving grounds in Yuma, AZ, they were
still using one to process payroll.

The poor maintenance contractor had to maintain the beast.

On Feb 1, 12:54 pm, "Zim Babwe"
<zimba...@doyoureallythinkthisisreal.comwrote:
>Not only did I use punch cards, but one time going up to the window to
give
my stack of cards to the operator, I dropped the cards! Imagine having
to
put them back in the right order? Nightmare!

I wonder if any of the IBM 029 card punch machines still exist?

"RobinS" <Rob...@NoSpam.yah.nonewrote in message

news:A8******************************@comcast.com ...
Oh, yeah? *I* used punchcards to write software! Oooooooooooh. (I
wonder
if anybody will get that.)
Robin S.
--------------------------------
<lord.zol...@gmail.comwrote in message
news:11*********************@h3g2000cwc.googlegro ups.com...
>On Jan 30, 12:57 pm, SomeGrayHa...@gmail.com wrote:
I agree about the documentation but when unfortunately for some of
us
Google did not exsits. You guys do not know how good you have it
>>I remember back when I was a kid I had to walk to school ... in the
snow ... ten miles .... up hill .... both ways .........
>You're lucky you had snow! When *I* was young, we only had ice
falling
out of the sky (snow had not yet been invented), and the ice pellets
were the size of grapefruits!- Hide quoted text -

- Show quoted text -


Feb 1 '07 #20

This discussion thread is closed

Replies have been disabled for this discussion.