From: John Spencer on 13 Feb 2010 13:52 You might want to wrap that in an abs function so it can handle negative integers also. Abs([Number]) MOD 2 or Abs([Number] MOD 2) If number is -3 then the original expression returns -1. Of course, if you are just testing for zero, then there is no problem with the original expression. John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County John W. Vinson wrote: > On Sat, 13 Feb 2010 00:55:01 -0800, Mansoor > <Mansoor(a)discussions.microsoft.com> wrote: > >> How should I write the following: >> >> IIf([Number] is even,0,1) >> Thanks in advance mansoor > > You don't need an IIF at all: just use the MOD operator, which returns the > remainder after a divison. [Number] MOD 2 will be equal to 0 if Number is > even, 1 if it is odd.
From: John Spencer on 13 Feb 2010 16:14 You can use either one of these expression to get the desired result IIF(([Number] Mod 2) = 0,0,1) Or Abs([Number] Mod 2) They both will return 0 or 1 if there is a number value in the number field. There is a slight difference it the number field is NULL. The first expression will return 1, the second will return Null. John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County Mansoor wrote: > Thank you Mr Spencer > but I need this condition > > IIf([Number] is even,0,1) > as a criteria to the following column > [FromNo] Mod 2 > > "John Spencer" wrote: > >> I think you will have to include parentheses to ensure the proper order of >> evaluation in the statement. >> (CLng([Number]) And 1) = 1 >> >> John Spencer >> Access MVP 2002-2005, 2007-2010 >> The Hilltop Institute >> University of Maryland Baltimore County >> >> Stefan Hoffmann wrote: >>> hi, >>> >>> On 13.02.2010 09:55, Mansoor wrote: >>>> How should I write the following: >>>> >>>> IIf([Number] is even,0,1) >>> Either use bit-masking or modulo-division: >>> >>> CLng([Number]) And 1 = 1 >>> >>> CLng([Number]) Mod 2 = 1 >>> >>> Both are testing for odd numbers. Depending of you numbers data type you >>> don't need the CLng() conversion. >>> >>> >>> mfG >>> --> stefan <-- >> . >>
From: Mansoor on 13 Feb 2010 17:44
Thank you very much Mr Spencer both solutions work perfectly Mansoor "John Spencer" wrote: > You can use either one of these expression to get the desired result > > IIF(([Number] Mod 2) = 0,0,1) > > Or > > Abs([Number] Mod 2) > > They both will return 0 or 1 if there is a number value in the number field. > There is a slight difference it the number field is NULL. The first > expression will return 1, the second will return Null. > > John Spencer > Access MVP 2002-2005, 2007-2010 > The Hilltop Institute > University of Maryland Baltimore County > > Mansoor wrote: > > Thank you Mr Spencer > > but I need this condition > > > > IIf([Number] is even,0,1) > > as a criteria to the following column > > [FromNo] Mod 2 > > > > "John Spencer" wrote: > > > >> I think you will have to include parentheses to ensure the proper order of > >> evaluation in the statement. > >> (CLng([Number]) And 1) = 1 > >> > >> John Spencer > >> Access MVP 2002-2005, 2007-2010 > >> The Hilltop Institute > >> University of Maryland Baltimore County > >> > >> Stefan Hoffmann wrote: > >>> hi, > >>> > >>> On 13.02.2010 09:55, Mansoor wrote: > >>>> How should I write the following: > >>>> > >>>> IIf([Number] is even,0,1) > >>> Either use bit-masking or modulo-division: > >>> > >>> CLng([Number]) And 1 = 1 > >>> > >>> CLng([Number]) Mod 2 = 1 > >>> > >>> Both are testing for odd numbers. Depending of you numbers data type you > >>> don't need the CLng() conversion. > >>> > >>> > >>> mfG > >>> --> stefan <-- > >> . > >> > . > |