How to determine if a number is odd or even?

R

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.
 
G

ge0193387

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
 
R

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?
 
L

lord.zoltar

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.
 
R

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
 
M

Mattias Sjögren

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
 
R

RobinS

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.
-----------------------------------------
 
R

rowe_newsgroups

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
 
L

lord.zoltar

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
 
S

SomeGrayHairs

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 .........
 
L

lord.zoltar

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!
 
R

raibeart

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.
 
B

Branco Medeiros

raibeart said:
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.
 
R

RobinS

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

Robin S.
--------------------------------
 
B

Bruce W. Darby

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
 
Z

Zim Babwe

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?
 
R

raibeart

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top