how do you find odd and evan numbers of a integer

Posted on 2004-11-18
Medium Priority
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
aka Pern
Question by:Johnny
  • 2
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
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

hope this will help....

LVL 44

Accepted Solution

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")
      MessageBox.Show("The Number " iVal & " Is Odd")
   end if

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.


Author Comment

ID: 12621791
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
LVL 44

Expert Comment

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


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



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