473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1334
* "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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
5
by: D. Shane Fowlkes | last post by:
This may be a very basic question but it's something I've never done before. I've looked at a couple of my favorite sites and books and can't find an answer either. I can write a Function to...
16
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
8
by: aleksandar.ristovski | last post by:
Hello all, I have been thinking about a possible extension to C/C++ syntax. The current syntax allows declaring a function that returns a value: int foo(); however, if I were to return...
2
by: mosesdinakaran | last post by:
Hi everybody, Today I faced a problem where I am very confused and I could not solve it and I am posting here.... My question is Is is possible to return a value to a particular function ...
5
by: codercoder | last post by:
Hello Helpers, I have a question about passing values through multiple C++ functions: Function A calls function B; Function B calls function C; Function C calls function D; D has two values...
20
by: Andrew Morton | last post by:
Is it possible to have two function declarations which take the same parameters but return different types depending on how the function is used? function f(x) as string ' return a string end...
2
ADezii
by: ADezii | last post by:
The incentive for this Tip was an Article by the amazing Allen Browne - I considered it noteworthy enough to post as The Tip of the Week in this Access Forum. Original Article by Allen Browne ...
6
by: SethM | last post by:
I have a stored procedure that returns a record set. I want to functionalize this so I can have multiple presentations of the same record set. However, I can not get rs_event.open StoreProc to pass...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.