Choose$

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > BuiltIn Functions > String functions >

Choose$

 

Description

 

Return one of several values, based upon the value of an index.

 

Syntax

 

s = Choose$(index, choice1 [, choice2] ...)

 

Returns

 

String

 

Parameters

 

Name

Type

Optional

Meaning

index

Numeric

No

Numeric expression whose value will be used as index for choosing string expression

choice1

String

No

An expression evaluated as string

choice2

String

Yes

...

...




 

Remarks

 

This function takes any number of choice arguments, and return the argument identified by index.  If index evaluates to one, choice1 is returned, if two, choice2 is returned, etc.  If index is less than one or greater than the number of choices provided, an empty string is returned accordingly.

 

Choose$ expects choices of string type.

 

Restrictions

 

See also

 

String Handling, SELECT, Choose

 

Examples

 

Thanks to Abraxas for the following script example

' Usage of the Choose$ Instruction example

' Returns the indexed String

 

Dim Mychoice   As DWORD VALUE 3

Dim Mystring   As String VALUE "Option 3"

Dim RetString  As String

 

RetString = CHOOSE$ (Mychoice, "Option 1""Option 2", MyString)

 

MSGBOX 0, RetString