Results 1 to 4 of 4

Thread: ALL & SOME function examples

Share/Bookmark
  1. #1
    Member marcuslee's Avatar
    Join Date
    Sep 2008
    Location
    Kansas, USA
    Age
    35
    Posts
    222
    Blog Entries
    2
    Rep Power
    31

    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
    50
    Posts
    8,091
    Blog Entries
    2
    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/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  3. #3
    Member marcuslee's Avatar
    Join Date
    Sep 2008
    Location
    Kansas, USA
    Age
    35
    Posts
    222
    Blog Entries
    2
    Rep Power
    31

    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
    35
    Posts
    222
    Blog Entries
    2
    Rep Power
    31

    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

Posting Permissions

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