|
-
Aug 24th, 2000, 07:24 PM
#1
Thread Starter
Frenzied Member
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.
-
Aug 24th, 2000, 07:45 PM
#2
Hyperactive Member
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.
-
Aug 24th, 2000, 07:57 PM
#3
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
-
Aug 25th, 2000, 02:10 AM
#4
Hyperactive Member
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.
-
Aug 25th, 2000, 03:43 AM
#5
Fanatic Member
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.
-
Aug 25th, 2000, 04:12 AM
#6
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
-
Aug 25th, 2000, 06:49 AM
#7
Thread Starter
Frenzied Member
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.
-
Aug 25th, 2000, 07:37 AM
#8
Hyperactive Member
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
-
Aug 25th, 2000, 07:44 AM
#9
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
-
Aug 25th, 2000, 07:50 AM
#10
Thread Starter
Frenzied Member
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.
-
Aug 25th, 2000, 07:59 AM
#11
No! If you use And it would only be visible if ALL images ARE visible. Now it becomes visible if ALL images are invisible.
-
Aug 25th, 2000, 08:06 AM
#12
Thread Starter
Frenzied Member
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.
-
Aug 25th, 2000, 08:27 AM
#13
Fanatic Member
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.
-
Aug 25th, 2000, 01:29 PM
#14
Thread Starter
Frenzied Member
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.
-
Aug 25th, 2000, 01:39 PM
#15
You got it.
-
Aug 25th, 2000, 01:49 PM
#16
Exactly and the code stated that he didn't want any to be visible so he used Not with the Or operator.
-
Aug 26th, 2000, 06:11 PM
#17
Thread Starter
Frenzied Member
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.
-
Aug 26th, 2000, 06:24 PM
#18
Frenzied Member
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."
-
Aug 26th, 2000, 08:37 PM
#19
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|