Choose (function)




Returns the expression at the specified index position.


The index parameter specifies which expression is to be returned. If index is 1, then expression1 is returned; if index is 2, then expression2 is returned, and so on. If index is less than 1 or greater than the number of supplied expressions, then Null is returned.

The Choose function returns the expression without converting its type. Each expression is evaluated before returning the selected one.


This example assigns a variable of indeterminate type to a.

Sub Main()

  Dim a As Variant
  Dim c As Integer
  c% = 2
  a = Choose(c%,"Hello, world",#1/1/94#,5.5,False)
  MsgBox "Item " & c% & " is '" & a & "'" 'Displays the date passed as parameter 2.
End Sub

See Also

Switch (function); IIf (function); If...Then...Else (statement); Select...Case (statement).

More information