Home All Groups Group Topic Archive Search About
Author
28 Jan 2006 11:27 AM
William Foster
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 ***

Author
28 Jan 2006 11:46 AM
Ken Tucker [MVP]
Hi,

        Dim strOddEven As String = IIf((100 Mod 2) = 0, "Even", "Odd")


Ken
-----------------
Show quoteHide quote
"William Foster" <nospam@devdex.com> wrote in message
news:Oly5e3$IGHA.524@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 ***
Author
28 Jan 2006 11:56 AM
William Foster
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 ***
Author
28 Jan 2006 12:05 PM
Herfried K. Wagner [MVP]
"William Foster" <nospam@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/>
Author
28 Jan 2006 12:34 PM
William Foster
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 ***
Author
28 Jan 2006 2:31 PM
guy
or simply

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

*guy*
Show quoteHide quote
"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 ***
>
Author
28 Jan 2006 4:04 PM
Scott M.
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.


Show quoteHide quote
"guy" <g**@discussions.microsoft.com> wrote in message
news:128D617A-CB03-4648-9A24-AE2036B2FF6F@microsoft.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 ***
>>
Author
28 Jan 2006 4:32 PM
Rocky
> 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.


Show quoteHide quote
"Scott M." <s-mar@nospam.nospam> wrote in message
news:u%23BFUSCJGHA.3492@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" <g**@discussions.microsoft.com> wrote in message
> news:128D617A-CB03-4648-9A24-AE2036B2FF6F@microsoft.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 ***
>>>
>
>
Author
28 Jan 2006 4:51 PM
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*

Show quoteHide quote
"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" <g**@discussions.microsoft.com> wrote in message
> news:128D617A-CB03-4648-9A24-AE2036B2FF6F@microsoft.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 ***
> >>
>
>
>
Author
28 Jan 2006 9:42 PM
Scott M.
Ahhh!

Thanks.


Show quoteHide quote
"guy" <g**@discussions.microsoft.com> wrote in message
news:26801C21-55AC-4FA6-ADFB-A67549486756@microsoft.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" <g**@discussions.microsoft.com> wrote in message
>> news:128D617A-CB03-4648-9A24-AE2036B2FF6F@microsoft.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 ***
>> >>
>>
>>
>>
Author
28 Jan 2006 5:20 PM
Herfried K. Wagner [MVP]
"Scott M." <s-mar@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/>
Author
30 Jan 2006 3:10 PM
Chris Dunaway
I think a more appropriate method would be this:

Public Function IsOdd(value As Integer) As Boolean
    Return ((value And 1) = 1)
End Function
Author
30 Jan 2006 4:51 PM
guy
yes i like that!

*guy*

Show quoteHide quote
"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
>
>
Author
29 Jan 2006 1:05 AM
Steve Wertz
Or before mod was invented...

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

-sw
Author
30 Jan 2006 12:35 PM
C-Services Holland b.v.
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