Combining constants


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Combining constants

  1. #1
    Chris Leffer Guest

    Combining constants


    I am using a CommonDialog control to open files, with some flags set. I noticed
    that if I use:
    CommonDialog1.Flags = cdlOFNHelpButton Or cdlOFNHideReadOnly

    I have the same result that:
    CommonDialog1.Flags = cdlOFNHelpButton + cdlOFNHideReadOnly

    Are there some important differences between the two approaches? How can
    they have the same effect?

    Thanks.

    Chris

  2. #2
    Don Bradner Guest

    Re: Combining constants

    "Chris Leffer" <chrisl@wank.com> wrote:

    >I am using a CommonDialog control to open files, with some flags set. I noticed
    >that if I use:
    >CommonDialog1.Flags = cdlOFNHelpButton Or cdlOFNHideReadOnly
    >
    >I have the same result that:
    >CommonDialog1.Flags = cdlOFNHelpButton + cdlOFNHideReadOnly
    >
    >Are there some important differences between the two approaches? How can
    >they have the same effect?


    In cases such as this, you are dealing with specific bits, and under normal
    circumstances they aren't going to be the same bit. So, if you have

    0001 and
    0010

    If you add them or Or them, you will get 0011. But let's suppose for some
    reason you have used two different constant names for the same actual value,
    such as

    0001 and
    0001

    Or'ing them will still be 0001, but adding them will be 0010 for an incorrect
    result.


    --
    Don Bradner
    don@arcatapet.com
    www.arcatapet.net (software)
    www.arcatapet.com (pet shop)

  3. #3
    Jonathan Wood Guest

    Re: Combining constants

    For the most part, the result is identical. However, logically, you are
    ORing bits together and so that's the method I stick with. There are
    mistakes you can make that will cause + to produce a wrong result (such as
    specifying the same bit twice in your expression).

    --
    Jonathan Wood
    SoftCircuits Programming
    http://www.softcircuits.com
    "Chris Leffer" <chrisl@wank.com> wrote in message
    news:3b75f55a$1@news.devx.com...
    >
    > I am using a CommonDialog control to open files, with some flags set. I

    noticed
    > that if I use:
    > CommonDialog1.Flags = cdlOFNHelpButton Or cdlOFNHideReadOnly
    >
    > I have the same result that:
    > CommonDialog1.Flags = cdlOFNHelpButton + cdlOFNHideReadOnly
    >
    > Are there some important differences between the two approaches? How can
    > they have the same effect?
    >
    > Thanks.
    >
    > Chris




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center