Playing with the mouse
#12
NOT a problem.

I'm in the camp that Tempo mentioned, use of home-made logical operators. This bitwise and XOR, NOT, etc. are fun, but can be more complicated than most of the conditions I code for.

For routines like this mouse or any simple condition that even only requires two conditions met, just everyone please remember to only use a numeric representation just once in the conditional statement...

Notice these differences if we want a non-zero response between i and j...

Code: (Select All)
i = 1: j = 1
PRINT i AND j ' bitwise returns 1
PRINT i AND j > 0 ' bitwise returns 1
PRINT i > 0 AND j > 0 ' numeric returns -1
PRINT "--------------------"
PRINT i AND j < 0 ' zero
PRINT i > 0 AND j > 0 ' negative one
PRINT "--------------------"
x$ = "abc"
find$ = "b"
j = INSTR(x$, find$)
IF j AND LEN(find$) THEN PRINT "1" ELSE PRINT "other"
IF j AND LEN(find$) <> 0 THEN PRINT "2" ELSE PRINT "other"
IF j <> 0 AND LEN(find$) THEN PRINT "3" ELSE PRINT "other"
IF j <> 0 AND LEN(find$) <> 0 THEN PRINT "4" ELSE PRINT "other"
PRINT "--------------------"
So especially in that last example the coder who thinks IF j AND LEN(find$) is the same as IF j <> 0 AND LEN(find$) <> 0 is going to get a sad awakening. If fact, 2nd and 3rd ways of writing the condition are still using a bitwise element, but are solid in there logic for this condition. I like using the second or third method, as it saves me some typing.

Pete
If eggs are brain food, Biden takes his scrambled.
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: 2 Guest(s)