User Tools

Site Tools


k10:k10.2:k10.2.4:start

10.2.4 Multiple Choose

The Choose(..) function returns the value of one of its arguments Result_i according to the integer value (>=1) of the selection. The following applies:

  • If the selection is 1, then Result_1 is returned.
  • If the selection is 2, then Result_2 will be returned and so on…. .
  • If the selection is less than or equal to 0 or there is no argument matching the selection, then NULL is returned.

10.2.4.1 Syntax for multiple selection

Value = Choose ( Choice , Result_1 , Result_2 [ , ... ] ) 

with the data types:

Value	→	Variant 
Choice	→	Integer 
Results  	→	Variant 

For example, the Choose control structure (…) fits well with a selection in a ComboBox or similar selection component that has the properties Index or Count and often leads to the sequence of numbers {0,1,2,3,…].. } with later transformation to {1,2,3,..}.

Example:

iEndOfLine = Choose(cmboxEndOfLine.Index + 1, gb.Unix, gb.Windows, gb.Mac) 

The constant gb. Unix has the value 1, gb. Windows has the value 2 and gb. Mac returns 3.

10.2.4.2 Examples for Multiple Selection Choose

X = 3 
PRINT Choose(X, "eins", "zwei", "drei", "vier") 
drei
X = 3 
PRINT IsNull(Choose(X * 2, "eins", "zwei", "drei", "vier")) 
True 
iMonat = 11 
PRINT Choose(iMonat, "Januar", "Februar", ...,  "November", "Dezember")   
November 

Alternatives for the last example would be to use the control structures with If… Then… Else or Select.. case or the use of a matrix with aMatrix = (“January”,“February”,…,“November”,“December”) and the selection via AktMonat = aMatrix[ iMonth + 1].

iMonat = 13 
PRINT Choose(iMonat, "Januar", "Februar", ...,  "November", "Dezember") 
NULL 
iMonat = 11 
PRINT Choose(iMonat, "Januar", "Februar", ..., "Oktober") 
NULL 

The second line replaces an IF..Then..Else block:

DIM sEnd AS String 
sEnd = Choose(CInt(iJumps < ijName) + 2, " ", "\n")  

The relation (iJumps < ijName) returns the values TRUE = -1 or FALSE = 0, so that the selection value - truth value multiplied by 2 - is either 1 or 2, and the string sEnd/ is assigned a blank character for the value 1 or a gb. NewLine (“\n”) for the value 2.

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k10/k10.2/k10.2.4/start.txt · Last modified: 23.09.2023 by honsek

Page Tools