|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Odd or EvenGood 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 *** 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 *** 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 *** "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/> 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 *** 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 *** > 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 *** >> > What does this do? the expression "value AND 1" doesn't seem to have any Huh? He was testing if the LSB (Least Significant Bit) was set.> 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. 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 *** >>> > > 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 *** > >> > > > 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 *** >> >> >> >> >> "Scott M." <s-mar@nospam.nospam> schrieb: F1, 'And' ;-).> 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. '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/> I think a more appropriate method would be this:
Public Function IsOdd(value As Integer) As Boolean Return ((value And 1) = 1) End Function 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 > > Or before mod was invented...
if int(value)/2=value/2 then isven=true -sw Steve Wertz wrote:
> Or before mod was invented... You might get problems with that because 2=2.0 can result in false. > > if int(value)/2=value/2 then isven=true > > -sw Therefore I've always used bit comparison like guy posted. -- Rinze van Huizen C-Services Holland b.v
Whats's the problem using a enum like this?
Is It Possible to Retrieve a List of Declared Variables? setting datagrid column widths in code? How to: Retrieving BuiltinDocumentProperties from Word Document Inheritance and function issue late binding problem with option strict What happen to Find in Files in VS2005? FileDownload with WebBrowser Control - disable the Save? Hpow to create a background process/application? WithEvent |
|||||||||||||||||||||||