Class Microsoft.VisualBasic.Interaction Syntax Dim result As Object = Choose(index, item_1[, item_2[..., item_n]])
index (required; Double) An expression that evaluates to the 1-based index of the object to choose from the list
item_1 to item_n (required; any) A comma-delimited list of values from which to choose or a ParamArray object that includes the items Description The Choose function 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. Usage at a Glance The item parameters can be variables, constants, literals, expressions, or function calls. Each item may be of a different type; the return value will be of type Object. If the rounded value of index does not correspond to an item in the list, the function returns Nothing. If index is not a whole number, it is rounded before being used. All item parameters are fully evaluated before they are considered as results for the Choose function. If they contain function calls, those functions will be called, even in the items that are not returned by the function. For instance, in the statement: result = Choose(methodToUse, ProcessFile(tempFileName), _ ProcessFile(mainFileName)) both calls to ProcessFile will always be performed, regardless of the value of methodToUse. However, at most, only one return value from among the function calls will be returned from the Choose function, and possibly none will be. This function does not support named arguments. By providing item_1 through item_n in the form of a ParamArray, the list of values can be expanded or contracted programmatically at runtime. Version Differences In VB 6, item_1 through item_n must only take the form of a comma-delimited list. In .NET, these arguments can also take the form of a ParamArray. In VB 6, an error occurs if index falls outside the range of choices. In .NET, this condition results in a return value of Nothing. See Also Switch Function |