PDA

View Full Version : CHOOSE and CALL used to do the same thing



marcuslee
09-09-2008, 04:14
This is an offshoot of this thread (http://community.thinbasic.com/index.php?topic=2021). So, you might want to read that one first.

I didn't know where to put this message since I'm not suggesting to put this in the help file. It is simply interesting that you can accomplish the same thing two different ways. There are always options.

The CHOOSE version:



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


And, the CALL version:



'Call functions in a loop

USES "Math"

DIM Index AS LONG
DIM RetNum AS DOUBLE

FOR Index = 1 TO 3
CALL "MyFunction" + Index( ) TO RetNum
MSGBOX 0, RetNum
NEXT

FUNCTION MyFunction1( )
FUNCTION = PI
END FUNCTION

FUNCTION MyFunction2( )
FUNCTION = PI * 2
END FUNCTION

FUNCTION MyFunction3( )
FUNCTION = PI * 3
END FUNCTION



Mark 8)

Michael Hartlef
09-09-2008, 07:01
That is one of the huge advantages of thinBasic. Flexibility!