Solved

# how do you find odd and evan numbers of a integer

Posted on 2004-11-18
Medium Priority
454 Views
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

Johnny
aka Pern
0
Question by:Johnny
• 2

LVL 14

Assisted Solution

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

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

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

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

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
Course of the Month13 days, 15 hours left to enroll