# Choose
{: .no_toc }

Selects and returns a value from a list of arguments by 1-based index.

Syntax: **Choose(** *index* **,** *choice-1* [ **,** *choice-2* **, ...** [ **,** *choice-n* ] ] **)**

*index*
: *required* Numeric expression that evaluates to a value between 1 and the number of available choices.

*choice*
: *required* **Variant** expression containing one of the possible choices.

If *index* is 1, **Choose** returns *choice-1*; if *index* is 2, it returns *choice-2*; and so on. If *index* is less than 1 or greater than the number of choices listed, **Choose** returns **Null**. Non-integer values of *index* are rounded to the nearest whole number before being evaluated.

> [!NOTE]
> An *index* outside the range of a **Single** raises error 6, *Overflow*, in twinBASIC, as in 64-bit VBA. VB6 returns **Null** for it.

> [!NOTE]
> **Choose** evaluates *every* choice in the list, not only the one it returns. Watch for side effects: a [**MsgBox**](/tB/Modules/Interaction/MsgBox.md) call inside any of the choices is invoked once per choice, not just for the selected one. To avoid this --- for example, when one of the branches would error out --- use the short-circuiting [**If**](/tB/Modules/Interaction/If.md) function instead.

### Common Errors

| Error | When |
|---|---|
| [94 (`&H5E`)](/Reference/Run-time-Errors.md#94), *Invalid use of Null* | *index* is **Null** |
| [6 (`&H6`)](/Reference/Run-time-Errors.md#6), *Overflow* | *index* is outside the range of a **Single** |

### Example

This example uses **Choose** to map a 1-based option index to a name.

```tb check_build
Function GetChoice(Ind As Integer) As String
    GetChoice = Choose(Ind, "Speedy", "United", "Federal")
End Function
```

### See Also

- [If](/tB/Modules/Interaction/If.md) function
- [IIf](/tB/Modules/Interaction/IIf.md) function
- [Switch](/tB/Modules/Interaction/Switch.md) function
