Playing with the mouse
#7
wow I  googled and found the order of execution of the logical operator in QB
from first to last: NOT AND OR XOR EQV IMP


is this the same order of execution made by QB64pe? I think so, but I wait for developers response.


if so the above expression is


1.  iActive AND ImouseX<500
2.      result OR ImouseX>600
3.              result OR ImouseY < 200
4.                      result OR ImouseY> 300


so in the case iActive = 0 and ImouseX = 400 and ImouseY = 100
1.    0 AND -1 --->0
2.        0 OR 0  --->0
3.            0 OR -1  --->-1
4.                -1 OR 0 --->-1
Here there is a logical error if you need that iActive must be True to execute the block of code.
(here is like you are saying: if it is active and the mouse is at least at one of these positions (X<500, X>600, Y<200, Y>300) you do this...)


but using the ( ) ,surrounding the OR group of conditions, you can avoid this unwanted result... if you use AND is because you want that all the 2 parameters must be true to get back true as result. 


while  you use EQV when it is important to you to manage all the conditions that are both  F or  both  T.

Here a test code that compares expression original AND + 3 OR ,with the use of ()  AND +(3 OR), the use of EQV (EQV + 3 OR), the use of () (EQV + (3OR))

Code: (Select All)
' we make some tests
Rem  AND versus EQV
Rem  wiki info https://qb64phoenix.com/qb64wiki/index.php/EQV

DefInt I
Dim iActive, ImouseX, ImouseY
iActive = 0
Locate 1, 1: Print " iActive  ImouseX   ImouseY"

For iActive = -1 To 0 Step 1
    ' the first run has iActive true while the second turn has iActive false
    ImouseX = 400: ImouseY = 100 ' ImouseX < 500 and ImouseY <200 are true
    Locate , 7: Print " "; iActive; "   "; ImouseX; "   "; ImouseY;

    If iActive And ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300 Then Print " AND works "; Else Print " AND rests";
    If iActive And (ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300) Then Print " AND + () work "; Else Print " AND +() rest";
    If iActive Eqv ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300 Then Print " EQV works "; Else Print " EQV rests";
    If iActive Eqv (ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300) Then Print " EQV +() works " Else Print " EQV +() rests "


    ImouseX = 600: ImouseY = 300 'All ImouseX and ImouseY are false
    Locate , 7: Print " "; iActive; "   "; ImouseX; "   "; ImouseY;
    If iActive And ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300 Then Print " AND works "; Else Print " AND rests ";
    If iActive And (ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300) Then Print " AND + () work "; Else Print " AND +() rest ";
    If iActive Eqv ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300 Then Print " EQV works "; Else Print " EQV rests ";
    If iActive Eqv (ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300) Then Print " EQV +() works " Else Print " EQV +() rests "

    ImouseX = 700: ImouseY = 400 ' ImouseX>600 and ImouseY > 300 are true
    Locate , 7: Print " "; iActive; "   "; ImouseX; "   "; ImouseY;

    If iActive And ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300 Then Print " AND works "; Else Print " AND rests ";
    If iActive And (ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300) Then Print " AND + () work "; Else Print " AND +() rest ";
    If iActive Eqv ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300 Then Print " EQV works "; Else Print " EQV rests ";
    If iActive Eqv (ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300) Then Print " EQV +() works " Else Print " EQV +() rests "
Next iActive


For iActive = -1 To 0 Step 1
    ' the first run has iActive true while the second turn has iActive false
    ImouseX = 400: ImouseY = 100 ' ImouseX < 500 and ImouseY <200 are true
    Locate , 7: Print " "; iActive; "   "; ImouseX; "   "; ImouseY;

    Print iActive And ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300, ;
    Print iActive And (ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300), ;
    Print iActive Eqv ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300; "       ";
    Print iActive Eqv (ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300)


    ImouseX = 600: ImouseY = 300 'All ImouseX and ImouseY are false
    Locate , 7: Print " "; iActive; "   "; ImouseX; "   "; ImouseY;
    Print iActive And ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300, ;
    Print iActive And (ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300), ;
    Print iActive Eqv ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300; "       ";
    Print iActive Eqv (ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300)


    ImouseX = 700: ImouseY = 400 ' ImouseX>600 and ImouseY > 300 are true
    Locate , 7: Print " "; iActive; "   "; ImouseX; "   "; ImouseY;

    Print iActive And ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300, ;
    Print iActive And (ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300), ;
    Print iActive Eqv ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300; "       ";
    Print iActive Eqv (ImouseX < 500 Or ImouseX > 600 Or ImouseY < 200 Or ImouseY > 300)

Next iActive


so the expression must pay attention to the order of execution of Logical operators to return the wanted result. As for all expression we can use () to modify the order of calculation.
Reply


Messages In This Thread
Playing with the mouse - by NasaCow - 12-11-2022, 07:59 AM
RE: Playing with the mouse - by Pete - 12-11-2022, 02:47 PM
RE: Playing with the mouse - by NasaCow - 12-11-2022, 03:03 PM
RE: Playing with the mouse - by SMcNeill - 12-11-2022, 02:51 PM
RE: Playing with the mouse - by TempodiBasic - 12-11-2022, 03:10 PM
RE: Playing with the mouse - by Pete - 12-11-2022, 04:50 PM
RE: Playing with the mouse - by mnrvovrfc - 12-11-2022, 06:36 PM
RE: Playing with the mouse - by Pete - 12-11-2022, 06:39 PM
RE: Playing with the mouse - by TempodiBasic - 12-11-2022, 05:39 PM
RE: Playing with the mouse - by SMcNeill - 12-11-2022, 08:21 PM
RE: Playing with the mouse - by NasaCow - 12-12-2022, 09:38 AM
RE: Playing with the mouse - by TempodiBasic - 12-11-2022, 06:24 PM
RE: Playing with the mouse - by Pete - 12-12-2022, 12:22 AM
RE: Playing with the mouse - by TempodiBasic - 12-13-2022, 02:45 PM



Users browsing this thread: 4 Guest(s)