Results 1 to 19 of 19

Thread: Am I wrong or... The facts about AND + OR

  1. #1

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Am I wrong or... (and?)


    Are the AND + the OR operators switched?

    I thought that if you used AND like:

    Code:
    If Condition1 = True AND Condition2 = true Then
    Results TRUE when they're both true

    and if the OR operator was used like this:

    Code:
    If Condition1 = True OR Condition2 = true Then
    Results TRUE when one of the 2 Conditions is True (Or both)

    But it seams to be switched in VB (or am I wrong?)
    I thought it was different in JavaScript.

    Maybe I'm getting crazy (or it may be the liquor I've been drinking tonight, a well)

    So please could someone explain this to me?

    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  2. #2
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458
    Hi,
    I don't think they're switched. Boolean algebra should work the same across all languages. Include code that you have a problem with so we can analize the problem.
    Thanks

    Tomexx.

  3. #3
    Guest
    Check this out:

    1 And 1 = 1
    0 And 1 = 0
    1 And 0 = 0
    0 And 0 = 0

    1 Or 1 = 1
    0 Or 1 = 1
    1 Or 0 = 1
    0 Or 0 = 0

    1 Xor 1 = 0
    0 Xor 1 = 1
    1 Xor 0 = 1
    0 Xor 0 = 0

  4. #4
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386
    It works the same in all programming languages.
    Although there are some slight differences what exactly is evaluated. VB evaluates the complete If line, while C checks the first boolean expression, and only if that's true, it will check the 2nd.
    Hope this helps

    Crazy D

  5. #5
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Maybe you think this because in the API you use

    val1 Or val2 Or val3

    When you would think that

    val1 And val2 And val3

    would make more sense.

    But you use Or like that in C++, so its really Micrososft's problem.
    Courgettes.

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by V(ery) Basic
    Maybe you think this because in the API you use
    val1 Or val2 Or val3
    When you would think that
    val1 And val2 And val3
    would make more sense.
    No using And doesn't make sense and here's why;
    What Or and And is really doing (in VB) is a bit comparing so 4 And 1 would be 0 but 4 Or 1 would be 5.
    5 And 1 = 1
    5 Or 1 = 5
    2 And 1 = 0
    2 Or 1 = 3

    Lets look at this with binary digits ( 4 Or 1 )
    0100 (=4)
    0001 (=1)
    ----------
    0101 (=5)

    The first digit is zero in both cases so that equals false or zero. The second digit is 1 in the first case and 0 in the second and when you do an Or operation that equals 1 and so on. Lets do the same with the And operator:

    0100 (=4)
    0001 (=1)
    ----------
    0000 (=0)

    None of the above digits are true in both cases so the result would be 0. Let try it with 5 Or 1:

    0101 (=5)
    0001 (=1)
    ----------
    0101 (=5)

    5 And 1:

    0101 (=5)
    0001 (=1)
    ----------
    0001 (=1)

    Best regards

  7. #7

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    1 And 1 = 1
    0 And 1 = 0
    1 And 0 = 0
    0 And 0 = 0

    1 Or 1 = 1
    0 Or 1 = 1
    1 Or 0 = 1
    0 Or 0 = 0
    Yeah that's how I thought it worked, but if you look at this reply by sam finch

    Code:
    With frmMain
      If Not(.imgHead.Visible Or .imgHead.Visible Or .imgArm.Visible Or .imgArms.Visible Or .imgLeg.Visible Or .imgFeet.Visible) Then
        .imgHead.Visible = True
      End If
    End with
    Would only make the imgHead.Visible True if none of the images are visible, so that's the part which confused me.

    So it doesn't make sense because regarding to the quoted part, I would have used and, how come?
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  8. #8
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386
    In the quoted part,I assume you want imgHead only be visible if all the others are invisible.
    I would have done something like
    Code:
    if imgHead.Visible = False And imgFeet.Visible = False ... Then
        imgHead.Visible = True
    End if
    As soon as you want to check if something is false, and put it in a way like Not (.Visible) I'm confused... ;-)
    "And" would be obvious to me.. but, with a Not in front of it, it has to be Or...
    Stupid example from the debug window:
    Code:
    ? iif(Not (False Or False), "A", "B") ' assume all img's are invisible
    ' displays an "A"
    
    ? iif(Not (True Or False), "A", "B") ' assume 1 of the img's is visible
    ' displays an "B"
    "A" means the imgHead.Visible code will be executed, "B" means it won't....


    So it's correct... the Not(imgHead.Visible Or imgFeet.Visible) only will make imgHead visible when all the img's are invisible...
    And is the same as imgHead.Visible = False And imgFeet.Visible = False
    Hope this helps

    Crazy D

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by Jop
    Code:
    With frmMain
      If Not(.imgHead.Visible Or .imgHead.Visible Or .imgArm.Visible Or .imgArms.Visible Or .imgLeg.Visible Or .imgFeet.Visible) Then
        .imgHead.Visible = True
      End If
    End with
    [/B]
    Change it to:
    Code:
    With frmMain
      If Not(((.imgHead.Visible Or .imgHead.Visible) Or (.imgArm.Visible Or .imgArms.Visible)) Or (.imgLeg.Visible Or .imgFeet.Visible)) Then
        .imgHead.Visible = True
      End If
    End with

  10. #10

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    hehe no it wasn't the code I needed, I just used it as an example, so it's the not what makes it using the or?, otherwhise you should use and?
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    No! If you use And it would only be visible if ALL images ARE visible. Now it becomes visible if ALL images are invisible.

  12. #12

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Yeah that's what I said

    Damn, it's getting confusing now
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  13. #13
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Originally posted by Joacim Andersson
    Originally posted by V(ery) Basic
    Maybe you think this because in the API you use
    val1 Or val2 Or val3
    When you would think that
    val1 And val2 And val3
    would make more sense.
    No using And doesn't make sense and here's why;
    What Or and And is really doing (in VB) is a bit comparing so 4 And 1 would be 0 but 4 Or 1 would be 5.
    5 And 1 = 1
    5 Or 1 = 5
    2 And 1 = 0
    2 Or 1 = 3

    Lets look at this with binary digits ( 4 Or 1 )
    0100 (=4)
    0001 (=1)
    ----------
    0101 (=5)

    The first digit is zero in both cases so that equals false or zero. The second digit is 1 in the first case and 0 in the second and when you do an Or operation that equals 1 and so on. Lets do the same with the And operator:

    0100 (=4)
    0001 (=1)
    ----------
    0000 (=0)

    None of the above digits are true in both cases so the result would be 0. Let try it with 5 Or 1:

    0101 (=5)
    0001 (=1)
    ----------
    0101 (=5)

    5 And 1:

    0101 (=5)
    0001 (=1)
    ----------
    0001 (=1)

    Best regards


    Thanks, but I did know that already. I was just saying that from a literary point of view, saying you wanted

    Val1 And Val2

    to be used would make more sense. I know that when you convert this into binary it is useless, but I was just saying that when you ask somebody to go shopping, you say I would like Bread And Milk, not Bread Or Milk. See?

    Sorry for any misunderstanding.


    Courgettes.

  14. #14

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Yeah the Or part would make it true when one of the Img's is Visible and the not would make it true none of the img's are Invisible.

    That's true right?

    So if I want that any of the IMG's are VISIBLE I would do

    Code:
    If (.imgHead.Visible Or .imgHead.Visible Or .imgArm.Visible Or .imgArms.Visible Or .imgLeg.Visible Or .imgFeet.Visible) Then
    and if I want all of the IMG's are visible I would do

    Code:
    If (.imgHead.Visible And .imgHead.Visible And .imgArm.Visible And .imgArms.Visible And .imgLeg.Visible And .imgFeet.Visible) Then
    So the "Not" expression confused me

    Or am I ****ing it all up again now?

    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  15. #15
    Guest
    You got it.

  16. #16
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Exactly and the code stated that he didn't want any to be visible so he used Not with the Or operator.

  17. #17

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986

    Talking

    Phew thanx guys, I thought I was getting crazy
    hahaha, well maybe I am.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  18. #18
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Maybe if you looked at a book on mathematical logic, boolean algebra, electronics (logic gates) or something similar it would make it clearer. There are quite a few logical equalities that you can use to manipulate a boolean expression. They should all be written down somewhere.

    I can't remember what the rule's called, but essentially:

    A.B = ¬(¬A+¬B)

    A+B = ¬(¬A.¬B)

    I expect you understand this already, but if you read something about it in a textbook it's all written very clearly and it's easier to remember.
    Harry.

    "From one thing, know ten thousand things."

  19. #19
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    It's all crazy man... I mean it's all crazy...............

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