?
Solved

how do you find odd and evan numbers of a integer

Posted on 2004-11-18
4
Medium Priority
?
454 Views
Last Modified: 2008-03-17
how do you find 1,3,5,7,9 from 1,2,3,4,5,6,7,8,9

or if a number is odd or not

searchNum = 1
SearchNumFind = Yes

searchNum = 2
SearchNumFind = NO

how do you do that in vb.net forms

thanks in advance
Johnny
aka Pern
0
Comment
Question by:Johnny
  • 2
4 Comments
 
LVL 14

Assisted Solution

by:Muhammad Ahmad Imran
Muhammad Ahmad Imran earned 1000 total points
ID: 12621616
I do not know vb.net but I try to figure it out, you should calculate the remainder of serchNum and if remainder is 0 then it is even else it is odd
like this

if mod(searchNum,2) = 0 then
SearchNumFind = No
else
SearchNumFind = Yes
end if

I use mod to calculate the remainder here
but it may be changed in vb.net it may be one of the following

searchNum mod 2 = 0 or
getRemainder(searchNum,2)

hope this will help....

Leo
0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 1000 total points
ID: 12621622
try this:


Dim iVal as Integer

for iVal = 1 to 9
   If iVal Mod 2 = 0 then
      MessageBox.Show("The Number " & ival & " Is Even")
   else
      MessageBox.Show("The Number " iVal & " Is Odd")
   end if
Next


the Mod operator returns the REMAINDER when the value on the Left is divided by the value on the Right, and when the value on the Right is 2, it acts as an Odd/Even Filter.

AW
0
 

Author Comment

by:Johnny
ID: 12621791
thx
i went with

                If (intArray Mod 2) = 0 Then TextBox1.Text &= "<tr BGCOLOR='aliceblue'>" & vbCrLf 'even
                If (intArray Mod 2) = 1 Then TextBox1.Text &= "<tr BGCOLOR='ghostwhite'>" & vbCrLf 'odd

and it works great

thx again
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12631048
this can be simplified:

 If (intArray Mod 2) = 0 Then TextBox1.Text &= "<tr BGCOLOR='aliceblue'>" & vbCrLf 'even
 If (intArray Mod 2) = 1 Then TextBox1.Text &= "<tr BGCOLOR='ghostwhite'>" & vbCrLf 'odd

to:

If intArray Mod 2 = 0 Then
        TextBox1.Text &= "<tr BGCOLOR='aliceblue'>" & vbCrLf 'even
Else
         TextBox1.Text &= "<tr BGCOLOR='ghostwhite'>" & vbCrLf 'odd
End If

AW



0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question