|
- Exiting from a SWITCH statement
- SWITCH with test on a condition
- OR keyword
- OTHER CASE keyword
SWITCH statement In french: SELON
SWITCH Quantity CASE 1: Comment = "Take advantage of our promotions: buy one, get one free" CASE 2: Comment = "Buy two products: get one free" OTHER CASE: Comment = "" END
SWITCH Value CASE 10: Trace(10) CASE 10<*<20: Trace("Included between 10 and 20") CASE >30: Trace("Greater than 30") END
SWITCH Quantity CASE TO 8: // Value less than or equal to 8 Comment = "A gift offered for each order" CASE 9,10: // Value equal to 9 or 10 Comment = "Take advantage of our promotions: buy one, get one free" CASE 11 TO 20 // Value included between 11 and 20 (inclusive) Comment = "Buy two products: get one free" CASE > 20: // Value greater than 20 Comment = "" END
// Simplified syntax: Combo_Sel contains numbers from 1 to 5 // A first name is displayed according to the selected number Value is int = COMBO_sel[COMBO_sel] Result1 is string = "" Result1 = SWITCH (Value, "Vince", "Emma", "Liz", "Freddy", ELSE "Not found")
Syntax
Full syntax Hide the details
SWITCH <Comparison variable> CASE <Expression 1>: <Action 1>
CASE <Expression 2>: <Action 2.1> <Action 2.2>
CASE <Expression 3> <Action 3.1> <Action 3.2> <Action 3.3>
CASE <Expression 4>, <Expression 5>: <Action 4>
CASE <Expression 6>, <Expression 7>: <Action 5>
CASE <Expression 8>, <Expression 9> <Action 6.1> <Action 6.2>
CASE <Minimum expression> TO: <Action 7>
CASE TO <Maximum expression>: <Action 8>
CASE <Minimum expression> TO <Maximum expression>: <Action 9>
CASE [= / ~= / ~~ / [= / > />= / < / <= / [~ / [~~ ] <Expression 10>: <Action 10>
CASE <Minimum expression> [<= * <=] [< * <=] [<= * <] [< * <] <Maximum expression>: <Action 11>
... [ OTHER CASE: <Action other case> OR OTHER CASE: <Action other case> OR OTHER CASE <Action other case> ] END
<SWITCH>: Marks the beginning of statement block. <Comparison variable>: Comparison variable (any type). <CASE>: Different comparison cases. <Expression N>: Value that must be compared to the comparison variable (same type as the comparison variable). <Action N>: Action to perform if the corresponding expression is equal to the comparison variable. Once this action has been performed, the process continues after the END keyword. <OTHER CASE>: Action to perform if the comparison variable is equal to no expression (optional). <END>: Marks the end of statement block.
Simplified syntax for an integer value of consecutive values Hide the details
<Result> = SWITCH (<Value>, <Result 1>, <Result 2>, ... <Result 3> [ELSE <Other Result>]) <Result> = SWITCH (<Value> <Result 1>, <Result 2>, ... )
<Result>: Value returned by SWITCH <SWITCH>: Marks the beginning of statement block. <Value>: Comparison variable (any type). <Result N>: Returned value. Returns <Result 1> if <Value> is set to 1, <Result 2> if <Value> is set to 2, ... <ELSE>: Used to process the case when no result corresponds to the value. A WLanguage error occurs if this case is not processed. <Other Result>: Value returned if no result corresponds to the value. Remarks Exiting from a SWITCH statement The BREAK SWITCH statement is used to exit from a SWITCH statement and to run the rest of the process. The syntax is as follows:
SWITCH <Expression> CASE <VALUE> ... IF <Condition> THEN BREAK SWITCH END END
For example:
SWITCH Quantity CASE 1 IF User = "Admin" THEN BREAK SWITCH END Comment = "Take advantage of our promotions: buy one, get one free" CASE 2: IF User = "Admin" THEN BREAK SWITCH END Comment = "Buy two products: get one free" OTHER CASE: Comment = "" END
SWITCH with test on a condition The result of a condition performed in a CASE statement can be checked in a SWITCH statement. This condition can be a complex condition containing calls to functions, ... For example:
SWITCH True // Check a complex condition CASE Value1 = 10 AND Value2 = 20: Trace(10) // Check a condition on a function CASE CheckCondition()
Note: to run a test on a simple condition, we recommend that you use the following syntax:
SWITCH Value CASE 10: Trace(10) CASE 10<*<20: Trace("Included between 10 and 20") CASE >30: Trace("Greater than 30") END
The OR keyword cannot be used to compare the value to an expression or to another one. The comma must be used. Example not to do:
Sub is int = 2 SWITCH Sub CASE 1 OR 2: Info("case 1 or 2") CASE 3: Info("case 3") OTHER CASE: Info("other case") END
to do:
Sub is int = 2 SWITCH Sub CASE 1,2: Info("case 1 or 2") CASE 3: Info("case 3") OTHER CASE: Info("other case") END
OTHER CASE must be the last statement used in the conditional SWITCH statement. Versions 18 and laterRadio Button control: automatic SWITCHWhen typing the SWITCH statement relative to a Radio Button control, the code editor automatically adds the CASE corresponding to the different options of the Radio Button control. The caption of each option is automatically added in line comment. Some examples: - Code for a Radio Button control that returns an integer: typing "SWITCH RADIO_Title" in the code editor displays:
- Code for a Radio Button control that returns a value: typing "SWITCH RADIO_TodaysMenu" in the code editor displays:
New in version 18Radio Button control: automatic SWITCHWhen typing the SWITCH statement relative to a Radio Button control, the code editor automatically adds the CASE corresponding to the different options of the Radio Button control. The caption of each option is automatically added in line comment. Some examples: - Code for a Radio Button control that returns an integer: typing "SWITCH RADIO_Title" in the code editor displays:
- Code for a Radio Button control that returns a value: typing "SWITCH RADIO_TodaysMenu" in the code editor displays:
Radio Button control: automatic SWITCH When typing the SWITCH statement relative to a Radio Button control, the code editor automatically adds the CASE corresponding to the different options of the Radio Button control. The caption of each option is automatically added in line comment. Some examples: - Code for a Radio Button control that returns an integer: typing "SWITCH RADIO_Title" in the code editor displays:
- Code for a Radio Button control that returns a value: typing "SWITCH RADIO_TodaysMenu" in the code editor displays:
This page is also available for…
|
|
|
| |
| Switch Case com n opções em cada case só usar virgula |
|
| SWITCH NUM CASE 2,4,52,63 .... CASE 43 ... CASE 55 ...
CASE 62,64,79,12 ... OTHER CASE ...
END
|
|
|
|
| |
| |
| |
|
| | https://youtu.be/NNuZF8I38i4 https://windevdesenvolvimento.blogspot.com/2019/09/dicas-2332-windev-webdev-mobile.html // SELECTING A ROW OF CAR_CARROSEL SWITCH CAR_CARROSEL CASE 1 Info("CADASTRO CLIENTE") CASE 2 Info("CADASTRO REPRESENTANTE") CASE 3 Info("CADASTRO TRANSPORTADORA") OTHER CASE END |
|
|
|
| |
| |
| |
|
| Exemplo Dia da Semana em Numeros |
|
| diaSemana is string = Lower(DateToDayInAlpha(gData)) SWITCH Lower(diaSemana) CASE "segunda-feira" : diaSemana = 1 CASE "terça-feira" : diaSemana = 2 CASE "quarta-feira" : diaSemana = 3 CASE "quinta-feira" : diaSemana = 4 CASE "sexta-feira" : diaSemana = 5 CASE "sábado" : diaSemana = 6 CASE "domingo" : diaSemana = 7 OTHER CASE : diaSemana = 0 END |
|
|
|
| |
| |
| |
|
| | SWITCH UF CASE "AC" : x = 1 CASE "AL" : x = 2 CASE "AP" : x = 3 CASE "AM" : x = 4 CASE "BA" : x = 5 CASE "CE" : x = 6 CASE "DF" : x = 7 CASE "ES" : x = 8 CASE "GO" : x = 9 CASE "MA" : x = 10 CASE "MT" : x = 11 CASE "MS" : x = 12 CASE "MG" : x = 13 CASE "PA" : x = 14 CASE "PB" : x = 15 CASE "PR" : x = 16 CASE "PE" : x = 17 CASE "PI" : x = 18 CASE "RJ" : x = 19 CASE "RN" : x = 20 CASE "RS" : x = 21 CASE "RO" : x = 22 CASE "RR" : x = 23 CASE "SC" : x = 24 CASE "SP" : x = 25 CASE "SE" : x = 26 CASE "TO" : x = 27 END ListSelectPlus(COMBO_T006_UF,x) |
|
|
|
| |
| |
| |
|
| | Exemplo SWITCH
EDT_resultado="" SWITCH EDT_idade CASE <= 18 EDT_resultado="Menor ou igual 18 anos" CASE >=60 EDT_resultado="Maior ou igual que 60" CASE 19 : EDT_resultado="19 anos" CASE 20 EDT_resultado="20 anos" CASE 21,22,23 EDT_resultado="21 22 23" CASE 24 TO 30 EDT_resultado="entre 24 a 30 anos" CASE 31 <*< 40 EDT_resultado="Entre 32 ate 39 anos" OTHER CASE END
//Blog com Video e Exemplo http://windevdesenvolvimento.blogspot.com.br/2016/10/aula-934-windev-comandos-2-switch.html https://www.youtube.com/watch?v=XAmIYCMb_ao
|
|
|
|
| |
| |
| |
| |
| |
| |
| | |
| |