Results 1 to 4 of 4

Thread: Usage of CHOOSE keyword

  1. #1
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    160

    Usage of CHOOSE keyword

    [code=thinbasic]
    ' Usage of the Choose Instruction example
    '
    ' Displays an indexed value
    '
    ' Written by Abraxas

    Dim Index as LONG value 3
    DIM RetNumber as LONG

    RetNumber = Choose (Index, 1,2,3)

    msgbox 0,RetNumber
    [/code]
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  2. #2

    Re: Usage of CHOOSE keyword

    Another CHOOSE example ---

    '
    ' Usage of the Choose Instruction example
    '
    ' Displays an indexed value
    '
    USES "MATH"

    DIM RetNumber as DOUBLE
    DIM Index as LONG

    For Index = 1 TO 3
    RetNumber = Choose (Index, Fun1, Fun2, Fun3)
    msgbox 0,RetNumber
    Next

    Function Fun1()
    Function = PI
    End Function

    Function Fun2()
    Function = PI*2
    End Function

    Function Fun3()
    Function = PI*3
    End Function

    XPS 1710

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

    Re: Usage of CHOOSE keyword

    Quote Originally Posted by GSAC3
    Another CHOOSE example ---
    [code=thinbasic]
    '
    ' Usage of the Choose Instruction example
    '
    ' Displays an indexed value
    '
    USES "MATH"

    DIM RetNumber as DOUBLE
    DIM Index as LONG

    For Index = 1 TO 3
    RetNumber = Choose (Index, Fun1, Fun2, Fun3)
    msgbox 0,RetNumber
    Next

    Function Fun1()
    Function = PI
    End Function

    Function Fun2()
    Function = PI*2
    End Function

    Function Fun3()
    Function = PI*3
    End Function
    [/code]
    That is an interesting. Just for conversation sake, are there any other ways to call functions in a similar loop fashion without using CHOOSE?

    Mark

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    Re: Usage of CHOOSE keyword

    CHOOSE just evaluate numeric expression so you can specify whatever valid numeric expression and it will be valid.

    Regarding other way of calling functions, have a look at CALL statement. It can be used to call function whose name is composed at runtime as a string expression. Very nice to execute function name dynamically. Example in http://community.thinbasic.com/index.php?topic=358.0
    But better to open a new thread on this
    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

Similar Threads

  1. Usage of the CHOOSE$ Keyword
    By Michael Clease in forum Samples for help file
    Replies: 3
    Last Post: 27-05-2007, 11:05

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
  •