Interaction.Choose(Double, Object[]) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Selects and returns a value from a list of arguments.
public:
static System::Object ^ Choose(double Index, ... cli::array <System::Object ^> ^ Choice);
public static object? Choose (double Index, params object?[] Choice);
public static object Choose (double Index, params object[] Choice);
static member Choose : double * obj[] -> obj
Public Function Choose (Index As Double, ParamArray Choice As Object()) As Object
Parameters
- Index
- Double
Required. Double. Numeric expression that results in a value between 1 and the number of elements passed in the Choice
argument.
- Choice
- Object[]
Required. Object
parameter array. You can supply either a single variable or an expression that evaluates to the Object
data type, to a list of Object
variables or expressions separated by commas, or to a single-dimensional array of Object
elements.
Returns
Selects and returns a value from a list of arguments.
Examples
This example uses the Choose
function to display a name in response to an index passed into the procedure in the Ind
parameter.
Function GetChoice(ByVal Ind As Integer) As String
GetChoice = CStr(Choose(Ind, "Speedy", "United", "Federal"))
End Function
Remarks
The Choose
function returns a member of the list passed in Choice()
, based on the value of Index
. The first member of the list is selected when Index
is 1. The last member of the list is selected when Index
is UBound
(Choice()
). If Index
is outside these limits, Choose
returns Nothing
.
If Index
is not a whole number, it is rounded to the nearest whole number before being evaluated.
You can use Choose
to look up a value in a list of possibilities.
Note
The expressions in the argument list can include function calls. As part of preparing the argument list for the call to Choose
, the Visual Basic compiler calls every function in every expression. This means that you cannot rely on a particular function not being called if a different expression is selected by Index
.