468,133 Members | 1,172 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

Return values from OR'd multiple function calls

I have 2 functions, CheckThis and CheckThat. Each function can return some
of the error codes in the Enum below (CheckThis can return 0, 1, 2 or 3 and
CheckThat can return 0, 4, 5 or 6). I'm trying to evaluate the following:

if CheckThis OR CheckThat then
Select Case ErrCode ...

obviously this won't work in the case of CheckThis returning a 2 and
CheckThat returning a 6, I'll get an 8 ...

I think Microsoft uses hex values for their error code enums (like 1, 2, 4,
8, 16, 32 etc.), but I'm not sure and would like to do this PROPERLY!

Any thoughts, tips, code, hyperlinks would be greatly appreciated!
Thanks in advance,
Tim

Enum ErrCode
OkeyDokey = 0
BadThis = 1
BadThat = 2
BadWhat = 3
BadDude = 4
BadBoy = 5
BadToTheBone = 6
End Enum

--
Tim Gallivan
If a man is in the forest and there are no women around, is he still wrong?
Nov 20 '05 #1
5 1145
* "Tim Gallivan" <no**********************@edu.gov.on.ca> scripsit:
I have 2 functions, CheckThis and CheckThat. Each function can return some
of the error codes in the Enum below (CheckThis can return 0, 1, 2 or 3 and
CheckThat can return 0, 4, 5 or 6). I'm trying to evaluate the following:

if CheckThis OR CheckThat then
Select Case ErrCode ...

obviously this won't work in the case of CheckThis returning a 2 and
CheckThat returning a 6, I'll get an 8 ...

I think Microsoft uses hex values for their error code enums (like 1, 2, 4,
8, 16, 32 etc.), but I'm not sure and would like to do this PROPERLY!

Any thoughts, tips, code, hyperlinks would be greatly appreciated!
Thanks in advance,
Tim

Enum ErrCode
OkeyDokey = 0
BadThis = 1
BadThat = 2
BadWhat = 3
BadDude = 4
BadBoy = 5
BadToTheBone = 6
End Enum


\\\
If (Result And ErrCode.BadThis) = ErrCode.BadThis Then
...
End If
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #2
Thanks Herfried, but not what I'm looking for.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bo*************@ID-208219.news.uni-berlin.de...
* "Tim Gallivan" <no**********************@edu.gov.on.ca> scripsit:
I have 2 functions, CheckThis and CheckThat. Each function can return some of the error codes in the Enum below (CheckThis can return 0, 1, 2 or 3 and CheckThat can return 0, 4, 5 or 6). I'm trying to evaluate the following:
if CheckThis OR CheckThat then
Select Case ErrCode ...

obviously this won't work in the case of CheckThis returning a 2 and
CheckThat returning a 6, I'll get an 8 ...

I think Microsoft uses hex values for their error code enums (like 1, 2, 4, 8, 16, 32 etc.), but I'm not sure and would like to do this PROPERLY!

Any thoughts, tips, code, hyperlinks would be greatly appreciated!
Thanks in advance,
Tim

Enum ErrCode
OkeyDokey = 0
BadThis = 1
BadThat = 2
BadWhat = 3
BadDude = 4
BadBoy = 5
BadToTheBone = 6
End Enum


\\\
If (Result And ErrCode.BadThis) = ErrCode.BadThis Then
...
End If
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>

Nov 20 '05 #3
* "Tim Gallivan" <no**********************@edu.gov.on.ca> scripsit:
Thanks Herfried, but not what I'm looking for.


Sorry, I pressed "Send" before completing the post...
I have 2 functions, CheckThis and CheckThat. Each function can return some of the error codes in the Enum below (CheckThis can return 0, 1, 2 or 3 and CheckThat can return 0, 4, 5 or 6). I'm trying to evaluate the following:
if CheckThis OR CheckThat then
Select Case ErrCode ...


This will only make sense if the "flags" are defined as 0, 1, 2, 4, 8,
16, ..., 2^n.

Simplified model:

DEZ BIN
0 0000
1 0001
2 0010
4 0100
8 1000

As you can see, every 2^n (n >= 0) sets a single bit in the binary
representation. Now you can use the binary operators 'Or' and 'And',
'Xor' and 'Not' to combine/... the numbers (bits).

You can _set_ a bit by 'Or'ing it with a constant, you can check a bit
by 'And'ing the number with a constant and comparing it to the original
value (or check if the result <> 0).

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #4
Thanks Herfried for the end of the post. That is prezactly what I trying to
do.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bo*************@ID-208219.news.uni-berlin.de...
* "Tim Gallivan" <no**********************@edu.gov.on.ca> scripsit:
Thanks Herfried, but not what I'm looking for.


Sorry, I pressed "Send" before completing the post...
I have 2 functions, CheckThis and CheckThat. Each function can return

some
of the error codes in the Enum below (CheckThis can return 0, 1, 2 or
3 and
CheckThat can return 0, 4, 5 or 6). I'm trying to evaluate the

following:

if CheckThis OR CheckThat then
Select Case ErrCode ...


This will only make sense if the "flags" are defined as 0, 1, 2, 4, 8,
16, ..., 2^n.

Simplified model:

DEZ BIN
0 0000
1 0001
2 0010
4 0100
8 1000

As you can see, every 2^n (n >= 0) sets a single bit in the binary
representation. Now you can use the binary operators 'Or' and 'And',
'Xor' and 'Not' to combine/... the numbers (bits).

You can _set_ a bit by 'Or'ing it with a constant, you can check a bit
by 'And'ing the number with a constant and comparing it to the original
value (or check if the result <> 0).

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>

Nov 20 '05 #5
Tim,
In addition to Herfried's comments about how to get it to work.

Microsoft's recommendation is to throw an exception if CheckThis or
CheckThat have a problem. This way the calling routine cannot ignore the
exception without have a Try Catch statement and doing nothing in the Catch
block of the Try Catch statement. Of course Exceptions may not be
appropriate.

If you have VB.NET 2003 an easy way of setting up the enum is:

<Flags()> _
Enum ErrCode
OkeyDokey = 1 << 0
BadThis = 1 << 1
BadThat = 1 << 2
BadWhat = 1 << 3
BadDude = 1 << 4
BadBoy = 1 << 5
BadToTheBone = 1 << 6
End Enum
Which shifts the 1 to the right the number of places given. The Flags
attribute lets the framework know that this enum should be treated as a set
of flags, and modifies how the Enum.ToString method behaves by default.

Hope this helps
Jay

"Tim Gallivan" <no**********************@edu.gov.on.ca> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... I have 2 functions, CheckThis and CheckThat. Each function can return some
of the error codes in the Enum below (CheckThis can return 0, 1, 2 or 3 and CheckThat can return 0, 4, 5 or 6). I'm trying to evaluate the following:

if CheckThis OR CheckThat then
Select Case ErrCode ...

obviously this won't work in the case of CheckThis returning a 2 and
CheckThat returning a 6, I'll get an 8 ...

I think Microsoft uses hex values for their error code enums (like 1, 2, 4, 8, 16, 32 etc.), but I'm not sure and would like to do this PROPERLY!

Any thoughts, tips, code, hyperlinks would be greatly appreciated!
Thanks in advance,
Tim

Enum ErrCode
OkeyDokey = 0
BadThis = 1
BadThat = 2
BadWhat = 3
BadDude = 4
BadBoy = 5
BadToTheBone = 6
End Enum

--
Tim Gallivan
If a man is in the forest and there are no women around, is he still wrong?

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

66 posts views Thread by Darren Dale | last post: by
5 posts views Thread by D. Shane Fowlkes | last post: by
16 posts views Thread by Nikolay Petrov | last post: by
8 posts views Thread by aleksandar.ristovski | last post: by
2 posts views Thread by mosesdinakaran | last post: by
20 posts views Thread by Andrew Morton | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.