Export (0) Print
Expand All

Interaction.Choose Method

Selects and returns a value from a list of arguments.

Namespace: Microsoft.VisualBasic
Assembly: Microsoft.VisualBasic (in microsoft.visualbasic.dll)

public static Object Choose (
	double Index,
	params Object[] Choice
)
public static Object Choose (
	double Index, 
	Object[] Choice
)
public static function Choose (
	Index : double, 
	... Choice : Object[]
) : Object

Parameters

Index

Required. Double. Numeric expression that results in a value between 1 and the number of elements passed in the Choice argument.

Choice

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.

Return Value

Selects and returns a value from a list of arguments.

For more detailed information, see the Visual Basic topic Choose Function.

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.

NoteNote

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.

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft