Name
Choose Function
Class
Microsoft.VisualBasic.Interaction
Named Arguments
No
Syntax
Choose(index, item_1[,item_2, ...[, item_n]])-
index(required; Single) An expression that evaluates to the (1-based) index of the object to choose from the list
-
item_1-item_n(required; any) A comma-delimited list of values from which to choose, or a ParamArray containing values from which to choose
Return Value
The object chosen from the list.
Description
Programmatically selects an object from a predefined list of objects (which are passed as parameters to the function) based on its ordinal position in the list. Using Choose is a simpler alternative to populating an array with fixed values.
Rules at a Glance
The list of items is based from 1, rather than the more usual VB default base of 0.
Because the list consists of objects, you can mix data types within the list; you are not forced to use the same data type for each item in the list. For example,
item_1can be a string, whileitem_2can be a long integer, anditem_3can be a floating point number.If the rounded value of
indexdoes not correspond to an item in the list, the function returns a null string.
Programming Tips and Gotchas
If
indexis not a whole number, it is rounded before being used.It is important to note that all items in the list are evaluated. Thus, if we use functions or expressions as parameters, all of the functions are called or all of the expressions are evaluated.
By providing
item_1throughitem_nin the form of a ParamArray, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access