View Full Version : Usage of CHOOSE keyword
Michael Clease
08-09-2008, 22:39
' 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
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
marcuslee
09-09-2008, 00:59
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
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 8)
ErosOlmi
09-09-2008, 03:48
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 ;)