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:
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.
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.
Die Funktion Choose(..) gibt entsprechend dem Integer-Wert (>=1) der Auswahl den Wert eines seiner Argumente Result_i zurück. Dabei gilt:
Value = Choose ( Choice , Result_1 , Result_2 [ , ... ] )
mit den Datentypen:
Value → Variant Choice → Integer Results → Variant
Der Einsatz der Kontrollstruktur Choose(..) passt zum Beispiel gut zu einer Auswahl bei einer ComboBox oder einer ähnlichen Auswahlkomponente, die über die Eigenschaften Index oder Count verfügen und führt häufig auf die Zahlenfolge {0,1,2,3,…} mit späterer Transformation auf {1,2,3,…}.
Beispiel:
iEndOfLine = Choose(cmboxEndOfLine.Index + 1, gb.Unix, gb.Windows, gb.Mac)
Die Konstante gb.Unix hat den Wert 1, gb.Windows den Wert 2 und gb.Mac liefert 3.
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
Alternativen für das letzte Beispiel wären die Verwendung der Kontrollstrukturen mit If..Then..Else oder Select..Case oder der Einsatz einer Matrix mit aMatrix = (“Januar”, “Februar”, …, “November”, “Dezember”) und der Auswahl über aktMonat = aMatrix[ iMonat + 1 ].
iMonat = 13 PRINT Choose(iMonat, "Januar", "Februar", ..., "November", "Dezember") NULL
iMonat = 11 PRINT Choose(iMonat, "Januar", "Februar", ..., "Oktober") NULL
Die zweite Zeile ersetzt einen IF..Then..Else-Block:
DIM sEnd AS String sEnd = Choose(CInt(iJumps < ijName) + 2, " ", "\n")
Die Relation (iJumps < ijName) liefert die Werte TRUE = -1 oder FALSE = 0. Somit wird der Auswahl-Wert – Wahrheitswert vermehrt um 2 – entweder 1 oder 2. Dem String sEnd wird entweder beim Wert 1 ein Leerzeichen oder aber beim Wert 2 ein gb.NewLine (“\n”) zugewiesen.