473,503 Members | 2,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Odd or Even

Good evening all,

Does anyone know how to find out whether a value is either odd or even
in the Visual Basic component of Visual Studio 2005. I have found the
Math and Information tools which provide some of the common functions
within other Microsoft packages such as Excel; however basic functions
like Odd and Even elude me.

Any assistance you may be able to provide would be greatly appreciated.

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***
Jan 28 '06 #1
13 7965
Hi,

Dim strOddEven As String = IIf((100 Mod 2) = 0, "Even", "Odd")
Ken
-----------------
"William Foster" <no****@devdex.com> wrote in message
news:Ol*************@TK2MSFTNGP09.phx.gbl...
Good evening all,

Does anyone know how to find out whether a value is either odd or even
in the Visual Basic component of Visual Studio 2005. I have found the
Math and Information tools which provide some of the common functions
within other Microsoft packages such as Excel; however basic functions
like Odd and Even elude me.

Any assistance you may be able to provide would be greatly appreciated.

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***

Jan 28 '06 #2
Ken,

Thank you for the quick reply, you have no idea how many silly
references there are to odd and even within the Visual Studio help, it
was driving me quite mad.

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***
Jan 28 '06 #3
"William Foster" <no****@devdex.com> schrieb:
Does anyone know how to find out whether a value is either odd or even
in the Visual Basic component of Visual Studio 2005. I have found the
Math and Information tools which provide some of the common functions
within other Microsoft packages such as Excel; however basic functions
like Odd and Even elude me.


\\\
If i Mod 2 = 0 Then
MsgBox("Even.")
Else
MsgBox("Odd.")
End If
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Jan 28 '06 #4
Herfried,

Thanks for your idea, Ken nailed the solution I needed first go though.

I should have written the question a couple of hours ago instead of
getting mad at the endless pages of help on functions that don't exist
in this suite.

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***
Jan 28 '06 #5
guy
or simply

Public Function IsOdd(value as Integer) as boolean
Return CBool(value And 1)
End Function

*guy*
"William Foster" wrote:
Good evening all,

Does anyone know how to find out whether a value is either odd or even
in the Visual Basic component of Visual Studio 2005. I have found the
Math and Information tools which provide some of the common functions
within other Microsoft packages such as Excel; however basic functions
like Odd and Even elude me.

Any assistance you may be able to provide would be greatly appreciated.

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***

Jan 28 '06 #6
What does this do? the expression "value AND 1" doesn't seem to have any
meaning. In an If statement you need a complete expression to have any
meaning (ie. value<5 AND 1>0). "value AND 1" will always return true, since
value is always = value and 1 is always = 1.

The Modulus (Mod) mathematical operand is designed to divide 2 numbers and
return the remainder, so taking a number and using mod 2 will indicate if
you have an even number if there is no remainder.
"guy" <gu*@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com...
or simply

Public Function IsOdd(value as Integer) as boolean
Return CBool(value And 1)
End Function

*guy*
"William Foster" wrote:
Good evening all,

Does anyone know how to find out whether a value is either odd or even
in the Visual Basic component of Visual Studio 2005. I have found the
Math and Information tools which provide some of the common functions
within other Microsoft packages such as Excel; however basic functions
like Odd and Even elude me.

Any assistance you may be able to provide would be greatly appreciated.

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***

Jan 28 '06 #7
> What does this do? the expression "value AND 1" doesn't seem to have any
meaning. In an If statement you need a complete expression to have any
meaning (ie. value<5 AND 1>0). "value AND 1" will always return true,
since value is always = value and 1 is always = 1.
Huh? He was testing if the LSB (Least Significant Bit) was set.
"Scott M." <s-***@nospam.nospam> wrote in message
news:u%****************@TK2MSFTNGP09.phx.gbl... What does this do? the expression "value AND 1" doesn't seem to have any
meaning. In an If statement you need a complete expression to have any
meaning (ie. value<5 AND 1>0). "value AND 1" will always return true,
since value is always = value and 1 is always = 1.

The Modulus (Mod) mathematical operand is designed to divide 2 numbers and
return the remainder, so taking a number and using mod 2 will indicate if
you have an even number if there is no remainder.
"guy" <gu*@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com...
or simply

Public Function IsOdd(value as Integer) as boolean
Return CBool(value And 1)
End Function

*guy*
"William Foster" wrote:
Good evening all,

Does anyone know how to find out whether a value is either odd or even
in the Visual Basic component of Visual Studio 2005. I have found the
Math and Information tools which provide some of the common functions
within other Microsoft packages such as Excel; however basic functions
like Odd and Even elude me.

Any assistance you may be able to provide would be greatly appreciated.

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***


Jan 28 '06 #8
guy
hi scott, and is used here as a bit operator

basically take two integers and the result has a bit set if the same bit is
set in both operators

with a logical 'Or' the result has a bit set if a bit is set in either
operator, see also Xor, Not ....

hth
*guy*

"Scott M." wrote:
What does this do? the expression "value AND 1" doesn't seem to have any
meaning. In an If statement you need a complete expression to have any
meaning (ie. value<5 AND 1>0). "value AND 1" will always return true, since
value is always = value and 1 is always = 1.

The Modulus (Mod) mathematical operand is designed to divide 2 numbers and
return the remainder, so taking a number and using mod 2 will indicate if
you have an even number if there is no remainder.
"guy" <gu*@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com...
or simply

Public Function IsOdd(value as Integer) as boolean
Return CBool(value And 1)
End Function

*guy*
"William Foster" wrote:
Good evening all,

Does anyone know how to find out whether a value is either odd or even
in the Visual Basic component of Visual Studio 2005. I have found the
Math and Information tools which provide some of the common functions
within other Microsoft packages such as Excel; however basic functions
like Odd and Even elude me.

Any assistance you may be able to provide would be greatly appreciated.

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***


Jan 28 '06 #9
"Scott M." <s-***@nospam.nospam> schrieb:
What does this do? the expression "value AND 1" doesn't seem to have any
meaning. In an If statement you need a complete expression to have any
meaning (ie. value<5 AND 1>0). "value AND 1" will always return true,
since value is always = value and 1 is always = 1.


F1, 'And' ;-).

'And' is a binary operator which will use a binary AND to combine both
'value' and '1'. The result is converted to a 'Boolean'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 28 '06 #10
Ahhh!

Thanks.
"guy" <gu*@discussions.microsoft.com> wrote in message
news:26**********************************@microsof t.com...
hi scott, and is used here as a bit operator

basically take two integers and the result has a bit set if the same bit
is
set in both operators

with a logical 'Or' the result has a bit set if a bit is set in either
operator, see also Xor, Not ....

hth
*guy*

"Scott M." wrote:
What does this do? the expression "value AND 1" doesn't seem to have any
meaning. In an If statement you need a complete expression to have any
meaning (ie. value<5 AND 1>0). "value AND 1" will always return true,
since
value is always = value and 1 is always = 1.

The Modulus (Mod) mathematical operand is designed to divide 2 numbers
and
return the remainder, so taking a number and using mod 2 will indicate if
you have an even number if there is no remainder.
"guy" <gu*@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com...
> or simply
>
> Public Function IsOdd(value as Integer) as boolean
> Return CBool(value And 1)
> End Function
>
> *guy*
> "William Foster" wrote:
>
>> Good evening all,
>>
>> Does anyone know how to find out whether a value is either odd or even
>> in the Visual Basic component of Visual Studio 2005. I have found the
>> Math and Information tools which provide some of the common functions
>> within other Microsoft packages such as Excel; however basic functions
>> like Odd and Even elude me.
>>
>> Any assistance you may be able to provide would be greatly
>> appreciated.
>>
>> Yours sincerely,
>>
>> William Foster
>>
>> *** Sent via Developersdex http://www.developersdex.com ***
>>


Jan 28 '06 #11
Steve Wertz wrote:
Or before mod was invented...

if int(value)/2=value/2 then isven=true

-sw


You might get problems with that because 2=2.0 can result in false.
Therefore I've always used bit comparison like guy posted.
--
Rinze van Huizen
C-Services Holland b.v
Jan 30 '06 #12
I think a more appropriate method would be this:

Public Function IsOdd(value As Integer) As Boolean
Return ((value And 1) = 1)
End Function

Jan 30 '06 #13
guy
yes i like that!

*guy*

"Chris Dunaway" wrote:
I think a more appropriate method would be this:

Public Function IsOdd(value As Integer) As Boolean
Return ((value And 1) = 1)
End Function

Jan 30 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
31597
by: bill drescher | last post by:
I have a long table and I want to have the alternating rows slightly different colors for clarity. Is there any way to avoid using a class designation in each tr ? (yes, it is for tabular data...
0
2405
by: Nathan | last post by:
Hi, I seem to having a peculiar problem with the display of odd and even pages in XSL-FO. Here is a small background of the problem. My xsl stylesheet mentions my fo:layout-master-set as ...
34
3930
by: Frederick Gotham | last post by:
I'm trying to write extremely efficient, fully portable algorithms to determine if an integer is odd or even. The most basic algorithms would be: #define IS_ODD(x) ((x) % 2) #define IS_EVEN(x)...
10
1949
by: Doug Robertson | last post by:
First off, I'm a hardware/OS guy. I just write code on the side and I'm completely self taught - so bear in mind my total lack of expertise. I have a program originally written in VB2003 using...
17
4596
by: Ron | last post by:
I want to write a program that will accept a number in a textbox for example 23578 and then in a label will display the sum of the odd and even number like this... the textbox containsthe number...
6
50241
by: Klaas Vantournhout | last post by:
Hi, I have a question, which is just out of interest. What is the fastest way to do an odd/even check with c++ and if needed assembler. Assume n is an unsigned integer like type (unsigned...
1
3088
by: chiefychf | last post by:
I'm working on a school project and I am having a few issues... The program calls for three arrays a,b,c that have to be sorted, then compared to even or odd and stored in arrays d & e, then merge...
30
29442
by: bdsatish | last post by:
The built-in function round( ) will always "round up", that is 1.5 is rounded to 2.0 and 2.5 is rounded to 3.0. If I want to round to the nearest even, that is my_round(1.5) = 2 # As...
18
4880
by: =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?= | last post by:
Hello. It seems a year is all it takes for one's proficiency in C++ to become too rusty. Professionally, I've been away from the language (and from programming in general), but I still preserve...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.