Results 1 to 8 of 8

Thread: Parse for flag values

  1. #1

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391

    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:
    1. 'like this?
    2.     lReturn = myFlag1 Or myFlag2
    3.  
    4.     ' or like this?
    5.     lReturn = myFlag1 And myFlag4 And myFlag5
    6.  
    7.    ' 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.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    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.

  3. #3

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    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:
    1. cdg1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer

    or in a MsgBox as buttons constants
    VB Code:
    1. 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.

  4. #4
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Create constants that are powers of two

    20
    21
    22
    ....
    231

    Each power of two sets (or clears) one bit in a long.

  5. #5

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    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.

  6. #6
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196
    You can AND you value with the flag - result would be 1 if it exists - 0 if not.

    HD

  7. #7

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391

    Thumbs up

    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.

  8. #8
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196

    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
  •  



Click Here to Expand Forum to Full Width