PC Review


Reply
Thread Tools Rate Thread

How to determine if a number is odd or even?

 
 
Ron
Guest
Posts: n/a
 
      29th Jan 2007
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.

 
Reply With Quote
 
 
 
 
ge0193387@otc.edu
Guest
Posts: n/a
 
      29th Jan 2007
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.com> wrote:
> 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.


 
Reply With Quote
 
Ron
Guest
Posts: n/a
 
      29th Jan 2007
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.com> wrote:
>
>
>
> > 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 -


 
Reply With Quote
 
lord.zoltar@gmail.com
Guest
Posts: n/a
 
      29th Jan 2007


On Jan 29, 5:35 pm, "Ron" <pts4...@yahoo.com> wrote:
> 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.

 
Reply With Quote
 
Ron
Guest
Posts: n/a
 
      30th Jan 2007
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.com> wrote:
>
> > 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.


 
Reply With Quote
 
Mattias Sjögren
Guest
Posts: n/a
 
      30th Jan 2007

>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.
 
Reply With Quote
 
RobinS
Guest
Posts: n/a
 
      30th Jan 2007
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" <(E-Mail Removed)> wrote in message
news:ub%(E-Mail Removed)...
>
>>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.



 
Reply With Quote
 
rowe_newsgroups
Guest
Posts: n/a
 
      30th Jan 2007
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.none> wrote:
> 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.org> wrote in messagenews:ub%(E-Mail Removed)...
>
>
>
> >>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.


 
Reply With Quote
 
lord.zoltar@gmail.com
Guest
Posts: n/a
 
      30th Jan 2007


On Jan 30, 6:54 am, "rowe_newsgroups" <rowe_em...@yahoo.com> wrote:
> 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

 
Reply With Quote
 
SomeGrayHairs@gmail.com
Guest
Posts: n/a
 
      30th Jan 2007
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"
<(E-Mail Removed)> wrote:

>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.none> wrote:
>> 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.org> wrote in messagenews:ub%(E-Mail Removed)...
>>
>>
>>
>> >>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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to determine the number? Eric Microsoft Excel Misc 8 5th Sep 2008 05:45 PM
Determine Row number =?Utf-8?B?Sk1heQ==?= Microsoft Excel Misc 3 3rd Jul 2007 01:40 PM
Determine if number is even or odd SGURDON Microsoft Access Queries 1 25th Mar 2004 11:20 PM
How To determine the number of CAL Kwong Microsoft Windows 2000 New Users 0 9th Oct 2003 04:32 PM
How do I determine row number of a cell containing a certain number? Ray Kostanty Microsoft Excel Discussion 6 19th Sep 2003 10:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:51 PM.