PDA

View Full Version : ALL & SOME function examples



marcuslee
08-09-2008, 14:38
Edit: I changed the name of the topic because I added an example of the SOME function in a later post, since the two are so similar.

As I practice and learn, I'll put my examples here for ones that don't have an example in the help file. If someone can come up with a better version than mine, great. If there is something you would like to change about mine, that's fine, too.




' ALL function example
' ----------------------

DIM n AS INTEGER, x AS INTEGER, y AS INTEGER, z AS INTEGER

x = 5

y = 4

z = 6

n = ALL( x = 5, x > y, x < z ) 'n will be 1 if all of these are true, 0 if one or more is false

IF n = 1 THEN
MSGBOX 0, "1st time True"
ELSE
MSGBOX 0, "1st time False"
END IF

n = ALL( x = 5, x > y, x > z ) 'this time it will be false because x is not greater than z

IF n = 1 THEN
MSGBOX 0, "2nd time True"
ELSE
MSGBOX 0, "2nd time False"
END IF


Mark :)

ErosOlmi
08-09-2008, 17:08
Thanks a lot Mark.

2 little notes.

1. if you need to declare multiple variables of the same type, just list them all and at the end add the AS clause. So:

DIM n AS INTEGER, x AS INTEGER, y AS INTEGER, z AS INTEGER
is shorted into

DIM n, x, y, z AS INTEGER

2. under 32 bit programming languages, it is always better to use LONG data type when you need to use integer class numbers. LONG are natively managed by processor, are better handled by thinBasic, are faster because in many cases thinBasic makes some internal optimization if LONG numbers are used.
Possibly use INTEGER numbers only if really needed, for example inside data structures used to pass in/out data to external functions (external DLL or windows API) but only because external data requires them to be used.
So:

DIM n, x, y, z AS LONG

Ciao
Eros

marcuslee
08-09-2008, 20:37
Thanks for the tips. I'll try to remember them ... :-\

Mark

marcuslee
08-09-2008, 21:30
Of course, something very similar can be used to show the SOME function.



' SOME function example
' ----------------------

DIM n, x, y, z AS LONG

x = 5

y = 4

z = 6

n = SOME( x = 6, x > y, x < z ) 'n will be 1 if just one of these is true, 0 if all are false

IF n = 1 THEN
MSGBOX 0, "1st time True"
ELSE
MSGBOX 0, "1st time False"
END IF

n = SOME( x = 4, x < y, x > z ) 'this time it will be false because none of them are true

IF n = 1 THEN
MSGBOX 0, "2nd time True"
ELSE
MSGBOX 0, "2nd time False"
END IF


Mark :)