# Thread: ALL & SOME function examples

1. ## ALL & SOME function examples

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.

[code=thinbasic]

' 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
[/code]

Mark

2. ## Re: ALL function example

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:
[code=thinbasic]DIM n AS INTEGER, x AS INTEGER, y AS INTEGER, z AS INTEGER[/code]
is shorted into
[code=thinbasic]DIM n, x, y, z AS INTEGER[/code]

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:
[code=thinbasic]DIM n, x, y, z AS LONG[/code]

Ciao
Eros

3. ## Re: ALL function example

Thanks for the tips. I'll try to remember them ... :-\

Mark

4. ## SOME function example

Of course, something very similar can be used to show the SOME function.

[code=thinbasic]
' 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
[/code]

Mark

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•