Results 1 to 4 of 4

Thread: ALL & SOME function examples

  1. #1
    Member marcuslee's Avatar
    Join Date
    Sep 2008
    Location
    Kansas, USA
    Age
    43
    Posts
    222
    Rep Power
    39

    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. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    Member marcuslee's Avatar
    Join Date
    Sep 2008
    Location
    Kansas, USA
    Age
    43
    Posts
    222
    Rep Power
    39

    Re: ALL function example

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

    Mark

  4. #4
    Member marcuslee's Avatar
    Join Date
    Sep 2008
    Location
    Kansas, USA
    Age
    43
    Posts
    222
    Rep Power
    39

    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

Similar Threads

  1. Ode examples are not working now
    By kryton9 in forum thinBasic General
    Replies: 14
    Last Post: 19-11-2007, 08:45
  2. Some thinBasic examples
    By ErosOlmi in forum TBGL module by Petr Schreiber
    Replies: 1
    Last Post: 02-03-2007, 02:49

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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