449,167 Members | 1,190 Online
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 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
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"

 P: n/a 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"

 P: n/a On Jan 29, 5:35 pm, "Ron" 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 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" 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 ina 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 4Or 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" >>Hello, I want to write some code to determine if a number entered ina 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 4Or 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" Hello, I want to write some code to determine if a number entered ina 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 4Or 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"

 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" You know, colleges should really add a course titled "Looking at theDocumentation 101" or even "Searching Google 101." Maybe then theseguys would quit asking us homework questions...Thanks,Seth Rowe On Jan 30, 2:02 am, "RobinS" Probably. It's the third time it's come up in the dotnet newsgroups in thepast week. It's like an epidemic. ;-)Robin S.-----------------------------------------"Mattias Sjögren" >Hello, I want to write some code to determine if a number entered ina 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 4Or if odd I want to add 2 to that number and multiply by 5 Homework? Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://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. -------------------------------- On Jan 30, 12:57 pm, SomeGrayHa...@gmail.com wrote: >I agree about the documentation but when unfortunately for some of usGoogle did not exsits. You guys do not know how good you have itI remember back when I was a kid I had to walk to school ... in thesnow ... 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" >On Jan 30, 12:57 pm, SomeGrayHa...@gmail.com wrote: >>I agree about the documentation but when unfortunately for some of usGoogle did not exsits. You guys do not know how good you have itI remember back when I was a kid I had to walk to school ... in thesnow ... ten miles .... up hill .... both ways ......... You're lucky you had snow! When *I* was young, we only had ice fallingout of the sky (snow had not yet been invented), and the ice pelletswere the size of grapefruits! Feb 1 '07 #15

 P: n/a *I* used a slide rule. :-O Robin S. ----------------------- "Bruce W. Darby" Oh, yeah? *I* used punchcards to write software! Oooooooooooh. (Iwonder if anybody will get that.)Robin S.-------------------------------->>On Jan 30, 12:57 pm, SomeGrayHa...@gmail.com wrote:I agree about the documentation but when unfortunately for some of usGoogle did not exsits. You guys do not know how good you have itI remember back when I was a kid I had to walk to school ... in thesnow ... ten miles .... up hill .... both ways ......... You're lucky you had snow! When *I* was young, we only had ice fallingout of the sky (snow had not yet been invented), and the ice pelletswere 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" >On Jan 30, 12:57 pm, SomeGrayHa...@gmail.com wrote: >>I agree about the documentation but when unfortunately for some of usGoogle did not exsits. You guys do not know how good you have itI remember back when I was a kid I had to walk to school ... in thesnow ... ten miles .... up hill .... both ways ......... You're lucky you had snow! When *I* was young, we only had ice fallingout of the sky (snow had not yet been invented), and the ice pelletswere 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" I remember back when I was a kid I had to walk to school ... in thesnow ... 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" Oh, yeah? *I* used punchcards to write software! Oooooooooooh. (Iwonder if anybody will get that.)Robin S.-------------------------------->>On Jan 30, 12:57 pm, SomeGrayHa...@gmail.com wrote:I agree about the documentation but when unfortunately for some of usGoogle did not exsits. You guys do not know how good you have itI remember back when I was a kid I had to walk to school ... in thesnow ... ten miles .... up hill .... both ways ......... You're lucky you had snow! When *I* was young, we only had ice fallingout of the sky (snow had not yet been invented), and the ice pelletswere the size of grapefruits! Feb 1 '07 #19

 P: n/a How long ago was that? Robin S. -------------------------------- "raibeart" Not only did I use punch cards, but one time going up to the window togivemy stack of cards to the operator, I dropped the cards! Imagine havingtoput them back in the right order? Nightmare!I wonder if any of the IBM 029 card punch machines still exist?"RobinS" On Jan 30, 12:57 pm, SomeGrayHa...@gmail.com wrote:I agree about the documentation but when unfortunately for some ofusGoogle 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 thesnow ... ten miles .... up hill .... both ways ......... >You're lucky you had snow! When *I* was young, we only had icefallingout of the sky (snow had not yet been invented), and the ice pelletswere the size of grapefruits!- Hide quoted text - - Show quoted text - Feb 1 '07 #20