Hello,
Is it possible to use or to create a function who gives a result of
True or False
for even or uneven numbers ?
Thank you in advance,
Jean-michel
|
|
0
|
|
|
|
Reply
|
imej-clavier (9)
|
2/11/2007 4:29:31 PM |
|
On 11 Feb 2007 08:29:31 -0800, "JeanMickey" <imej-clavier@wanadoo.fr>
wrote:
>Hello,
>Is it possible to use or to create a function who gives a result of
>True or False
>for even or uneven numbers ?
>
>Thank you in advance,
>
>
> Jean-michel
Use the mod function.
Richard
Web pages: http://www.caravanningnow.co.uk/ for caravanning,
http://www.rcole.org/ for my personal web site and
http://www.homeindorset.co.uk because I love the email address.
--
MURDERERS Need to dispose of a body? Simply parcel it up and post it to
yourself via DHL. You will never see it again. - 'Viz' top tip
|
|
0
|
|
|
|
Reply
|
ispcrco1 (162)
|
2/11/2007 4:38:47 PM
|
|
On 11 Feb 2007 08:29:31 -0800, "JeanMickey" <imej-clavier@wanadoo.fr>
wrote:
>Hello,
>Is it possible to use or to create a function who gives a result of
>True or False
>for even or uneven numbers ?
>
>Thank you in advance,
Are they Integers ?
If so : X And 1 = 1 if X is odd
|
|
0
|
|
|
|
Reply
|
erewhon2 (1042)
|
2/11/2007 4:51:08 PM
|
|
In response to the post:
On 11 Feb 2007 08:29:31 -0800, "JeanMickey" <imej-clavier@wanadoo.fr>
stated...and I replied:
>Hello,
>Is it possible to use or to create a function who gives a result of
>True or False
>for even or uneven numbers ?
>
>Thank you in advance,
>
>
> Jean-michel
As previously stated, the mod function will give you a numeric answer
of Odd or Even. To answer the question on creating a function, yes it
is possible. A further question would be... "which of the 2 states
will be True and which False?"
Private Function Odd_Even(X) As Boolean
Odd_Even = CBool( Iif( Val( X ) MOD 2,"#TRUE#", "#FALSE#" ) )
End Function
HTH,
Shell
|
|
0
|
|
|
|
Reply
|
drshell (102)
|
2/11/2007 6:51:26 PM
|
|
On Feb 11, 10:29 am, "JeanMickey" <imej-clav...@wanadoo.fr> wrote:
> Hello,
> Is it possible to use or to create a function who gives a result of
> True or False
> for even or uneven numbers ?
>
> Thank you in advance,
>
> Jean-michel
Since the Mod operator will divide two numbers and return the
remainder, why not just Mod the number in question, dividing by 2.
If the remainder is zero, the number is even, and if the remainder is
1, then the number was odd.
E.g.,
If NumberInQuestion Mod 2 = 1 Then
OddNo = True
Else
OddNo = False
End If
|
|
0
|
|
|
|
Reply
|
secondar (59)
|
2/11/2007 10:01:42 PM
|
|
"JeanMickey" <imej-clavier@wanadoo.fr> skrev i en meddelelse
news:1171211371.317787.200550@j27g2000cwj.googlegroups.com...
> Hello,
> Is it possible to use or to create a function who gives a result of
> True or False
> for even or uneven numbers ?
>
I have always used :
If int(value / 2)= value / 2 then even = true else even = false
|
|
0
|
|
|
|
Reply
|
FuckOff6018 (12)
|
2/13/2007 1:56:59 PM
|
|
Good evening
I've always used the following:
If number AND 1 =0 then even=true else even=false
Darryl
"Desserten" <FuckOff@SpamFucker.Zero> wrote in message
news:45d1c3ab$0$223$edfadb0f@dread11.news.tele.dk...
>
> "JeanMickey" <imej-clavier@wanadoo.fr> skrev i en meddelelse
> news:1171211371.317787.200550@j27g2000cwj.googlegroups.com...
>> Hello,
>> Is it possible to use or to create a function who gives a result of
>> True or False
>> for even or uneven numbers ?
>>
>
> I have always used :
>
> If int(value / 2)= value / 2 then even = true else even = false
>
|
|
0
|
|
|
|
Reply
|
nmac_inc1 (5)
|
2/14/2007 10:21:20 AM
|
|
Just about everyone's had a go at this, so I don't want to be left out
<vbg>
Public Function bEven(lValue As Long) As Boolean
bEven = ((lValue And 1) = 0)
End Function
Tony Proctor
"JeanMickey" <imej-clavier@wanadoo.fr> wrote in message
news:1171211371.317787.200550@j27g2000cwj.googlegroups.com...
> Hello,
> Is it possible to use or to create a function who gives a result of
> True or False
> for even or uneven numbers ?
>
> Thank you in advance,
>
>
> Jean-michel
>
|
|
0
|
|
|
|
Reply
|
tony_proctor (250)
|
2/14/2007 4:40:06 PM
|
|
> Just about everyone's had a go at this, so I don't want to be left out
> <vbg>
I don't want to be left out either<g>. Let's see... Hmm!... My favorite has
already been posted.... What to do?... I guess I'll have to post a
non-traditional method... Let's see now... I know!...
Function IsEven(Value As Long) As Boolean
IsEven = (Right$(CStr(Value), 1) Like "[02468]")
End Function
Function IsOdd(Value As Long) As Boolean
IsOdd = (Right$(CStr(Value), 1) Like "[13579]")
End Function
<vbg>
Rick
|
|
0
|
|
|
|
Reply
|
rickNOSPAMnews (1770)
|
2/14/2007 6:30:16 PM
|
|
"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
message news:G5ydneBiiI-kyE7YnZ2dnUVZ_segnZ2d@comcast.com...
>> Just about everyone's had a go at this, so I don't want to be left out
>> <vbg>
>
> I don't want to be left out either<g>. Let's see... Hmm!... My favorite
> has already been posted.... What to do?... I guess I'll have to post a
> non-traditional method... Let's see now... I know!...
>
> Function IsEven(Value As Long) As Boolean
> IsEven = (Right$(CStr(Value), 1) Like "[02468]")
> End Function
>
> Function IsOdd(Value As Long) As Boolean
> IsOdd = (Right$(CStr(Value), 1) Like "[13579]")
> End Function
>
> <vbg>
>
> Rick
>
What about:
Function IsOdd(ByRef MyNumber as Variant) As Variant
Dim Message, Title, Default
Message = "Is this an odd number" ' Set prompt.
Title = "InputBox Demo" ' Set title.
Default = "1" ' Set default.
' Display message, title, and default value.
IsOdd = InputBox(Message, Title, Default)
End Function
|
|
0
|
|
|
|
Reply
|
harry6306 (13)
|
2/16/2007 6:05:43 AM
|
|
|
9 Replies
32 Views
(page loaded in 0.181 seconds)
|