|
-
Sep 18th, 2002, 08:43 AM
#1
Thread Starter
Hyperactive Member
Parse for flag values
I have a function that I want to return a long value which is
made up of one or more constant values that I've declared.
I want the calling function to be able to parse that value and
detect which flags were included in the return and take appropriate action.
Can anyone explain to me what conventions I should use in declaring my constants (odd numbers only? prime numbers? etc)
as well as how I should build my return value?
VB Code:
'like this?
lReturn = myFlag1 Or myFlag2
' or like this?
lReturn = myFlag1 And myFlag4 And myFlag5
' or something else?
I also need to know how to parse the return value to know which flag constants were present. I think that it would be some sort of 'Or' statement, but I'd like to be sure.
Thanks.
And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.
-
Sep 18th, 2002, 09:06 AM
#2
What is that you really want to do? Do you just want to know using one return value that one or more values have been set? In that case if you have say 5 values return a string of 5 zeros and ones, with a one indicating that a specific value has been set.
-
Sep 18th, 2002, 09:15 AM
#3
Thread Starter
Hyperactive Member
I could do something like that, but I'd rather learn the other way.
For example, if you pass multiple flags to the Common Dialog Control
VB Code:
cdg1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
or in a MsgBox as buttons constants
VB Code:
MsgBox "Hello", vbExclamation Or vbYesNoCancel
how does it parse through the value made from the Or statement to determine which flags are included?
And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.
-
Sep 18th, 2002, 09:20 AM
#4
Frenzied Member
Create constants that are powers of two
20
21
22
....
231
Each power of two sets (or clears) one bit in a long.
-
Sep 18th, 2002, 09:21 AM
#5
Thread Starter
Hyperactive Member
Ok, that makes sense. What would I use to detect which bits were set/cleared?
And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.
-
Sep 18th, 2002, 09:28 AM
#6
Addicted Member
You can AND you value with the flag - result would be 1 if it exists - 0 if not.
HD
-
Sep 18th, 2002, 09:33 AM
#7
Thread Starter
Hyperactive Member
Got it, except that (lReturn And myFlag2) equals myFlag2 or 0, not 1 (unless myFlag2 == 1)
Thanks guys.
And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.
-
Sep 18th, 2002, 09:35 AM
#8
Addicted Member
Doh!
Sorry about that - I wasn't thinking! Of course it gives the flag back.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|