Results 1 to 5 of 5

Thread: Check against a value

Hybrid View

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Check against a value

    I have a variable called, for example, "lstate". It can be a combination of ODS_DEFAULT, ODS_SELECTED, ODS_FOCUS, etc.
    Now, I want to if it has ODS_SELECTED it in.
    Here is how I am doing:
    PHP Code:
    if(lstate && ODS_SELECTED)
    {
    //ODS_SELECTED is in there

    Is the above checking right?
    Baaaaaaaaah

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    I think if each of the possible values is a power of 2, this is the way...
    PHP Code:
    if ((lstate ODS_SELECTED) == ODS_SELECTED)
    {
    //...ODS_SELECTED is in there...

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    jim mcnamara
    Guest
    Crptc is right. It will only work if the constant sets a bit on that no other constant sets. Also use the bit-wise & operator, not the && boolean operator

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Thumbs up

    Originally posted by jim mcnamara
    Crptc is right.
    All right...1 out of 2500 ain't too shabby.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Thanks, especially clearing about that bitwise operator...was messing up with them and inversing them.
    Anyways, my code still isn't doing what I want it to but I guess it's some other problem...
    Baaaaaaaaah

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