Choose Function Example

Category:
Miscellaneous
Type:
Snippets
Difficulty:
Beginning
Author:
Intelligent Solutions Inc.

Version Compatibility:

More information:
The Choose function evaluates an numeric argument and a list. The numeric argument should be within the range of the number of values in the list (e.g., if there are four arguments in the list, the numeric argument should be between 1-4). If the numeric argument is within this range, choose returns the given item in the list (e.g., if the numeric argument is 3, Choose returns the third item in the list). If the numeric argument is less than one or greater than the number of items in the list, Choose returns null.

Choose can be useful for writing more concise code as compared to long select statments or initializing long static arrays, as the examples below illustrate.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: