Playing with the mouse
#14
@Nasacow
hi, play with this general purpouse function made with EQV and the difference with that made with AND...
Code: (Select All)
Print "EQV"
Print IsInTheRangeEQV(3, 9, 7) ' 7 is in the range 3-9
Print IsInTheRangeEQV(9, 3, 7) ' 7 is in the range 3-9
Print IsInTheRangeEQV(3, 7, 9) ' 9 is above range 3-7
Print IsInTheRangeEQV(9, 7, 3) ' 3 is under range 7-9

Print "------------------"
Print "AND"
Print IsInTheRangeAND(3, 9, 7) ' 7 is in the range 3-9
Print IsInTheRangeAND(9, 3, 7) ' 7 is in the range 3-9
Print IsInTheRangeAND(3, 7, 9) ' 9 is above range 3-7
Print IsInTheRangeAND(9, 7, 3) ' 3 is under range 7-9
Print "if you look closely at code you can see what advantage EQV brings up versus AND for this kind of test"
Print "--------OutOfRangeEQV"
Print OutOfRangeEQV(3, 7, 1)
Print OutOfRangeEQV(7, 3, 1)
Print OutOfRangeEQV(3, 9, 7)
Print OutOfRangeEQV(9, 3, 6)
Print OutOfRangeEQV(3, 7, 9)
Print OutOfRangeEQV(7, 3, 9)
Sleep 2
Cls , 2
Locate 1, 1
Print "now we go to test in action"
Sleep 2
Cls , 3
For a = 1 To 10
    Locate 10 + a, 20: Print Space$(20)
Next a

While _MouseButton(2) = 0
    If _MouseInput Then
        Locate 1, 20: Print Space$(30);
        If IsInTheRangeEQV(10, 21, _MouseY) Then
            If IsInTheRangeEQV(19, 41, _MouseX) Then
                Locate 1, 20: Print Space$(30);
                Locate 1, 20: Print "the mouse is in the box!"
            End If
        End If
    End If
    'clear the buffer of mouseinput
    While _MouseInput: Wend
Wend
Cls , 0
Print " end of demo"
End

Function IsInTheRangeAND (Min As Integer, Max As Integer, Value As Integer)
    ' this function returns true if Value is less than Max and more than Min
    If (Min < Value) And (Value < Max) Then IsInTheRangeAND = -1 Else IsInTheRangeAND = 0
End Function


Function IsInTheRangeEQV (Min As Integer, Max As Integer, Value As Integer)
    ' this function returns true if Value is less than Max and more than Min
    If (Min < Value) Eqv (Value < Max) Then IsInTheRangeEQV = -1 Else IsInTheRangeEQV = 0
End Function

Function OutOfRangeEQV (Min As Integer, Max As Integer, Value As Integer)
    ' this function returns true if Value is more than Max and Min
    If (Min < Value) Eqv (Max < Value) Then IsMaxEQV = -1 Else IsMaxEQV = 0
    ' If (Min > Value) Eqv (Min > Max) Then IsMinEQV = -1 Else IsMinEQV = 0 REM this brings to the same results
End Function

About Logical test versus Bitwise test... the second is for who works with &H or &B digital numbers... ASM/C at low level and any lowlevel language... the logical test is for instruction of choice in the code... you can use only the direct comparison operators (= <> > < >= <= ) or also logical operators...

IMHO in Qbasic and in QB64 AND/OR/XOR/NOT/EQV/IMP  work as bitwise mode when you pass them numbers... and as logical mode when you pass comparisons.
Fine to learn from you boys of QB64! Heart
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: 10 Guest(s)