PC SOFT

WINDEV的在线文档

  • Exiting from a SWITCH statement
  • SWITCH with test on a condition
  • OR keyword
  • OTHER CASE keyword
文档页面当前正在翻译。对于此延迟我们深表歉意。
您可以自愿地帮助我们翻译您想要的文档段落,然后只需通过以下地址与我们联系:info@cn.windev.com
产品
WinDevWebDev-服务器代码WebDev-浏览器代码WinDev Mobile报表和查询
平台
WindowsLinuxWindows MobileWindows PhoneWindows Store appsAndroidAndroid Widget iPhone/iPad
语言
JavaPHPAjax用户代码(MCU)外部语言
数据库
HFSQLHFSQL Client/Server存储过程HF 5.5OLE DBODBC本地访问

The 根据 statement is used to choose the action that will be run according to the value of an expression.

Two syntaxes are available for this statement:

  • Full syntax
  • Simplified syntax for an integer value of consecutive values.
18版本和更高版本
WinDevWindows Store apps This feature is available in Windows Store apps mode.
18新版本
WinDevWindows Store apps This feature is available in Windows Store apps mode.
WinDevWindows Store apps This feature is available in Windows Store apps mode.
例子
根据Quantity
情况1,那么Comment"Take advantage of our promotions: buy one, get one free"
情况2,那么Comment"Buy two products: get one free"
其他情况,那么Comment""
结束

根据Value
情况10,那么跟踪10
情况10小于*小于20,那么跟踪"Included between 10 and 20"
情况大于30,那么跟踪"Greater than 30"
结束

根据Quantity
情况直到8,那么 // Value less than or equal to 8
Comment"A gift offered for each order"
情况910,那么 // Value equal to 9 or 10
Comment"Take advantage of our promotions: buy one, get one free"
情况11直到20 // Value included between 11 and 20 (inclusive)
Comment"Buy two products: get one free"
情况大于20,那么 // Value greater than 20
Comment""
结束

// Simplified syntax: Combo_Sel contains numbers from 1 to 5
// A first name is displayed according to the selected number
Value整数型COMBO_selCOMBO_sel
Result1字符串型""
Result1=根据(Value"Vince""Emma""Liz""Freddy",否则"Not found"

语法

Full syntax 隐藏详细信息

 根据 <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 the 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 结束 keyword.
<OTHER CASE>:
Action to perform if the comparison variable is equal to no expression (optional).
<END>:
Marks the end of the statement block.

Simplified syntax for an integer value of consecutive values 隐藏详细信息

 根据 (<Value>, <Result 1>, <Result 2>, ... <Result 3> [ELSE <Other result>])
SWITCH (<Value>
      <Result 1>,
      <Result 2>,
      ...
      )

<SWITCH>:
Marks the beginning of the 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.

注意

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:

根据Quantity
情况1
如果User"Admin",那么
跳出根据
结束
Comment"Take advantage of our promotions: buy one, get one free"

情况2,那么
如果User"Admin",那么
跳出根据
结束
Comment"Buy two products: get one free"

其他情况,那么Comment""
结束

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:

根据
// Check a complex condition
情况Value110并且Value220,那么跟踪10
// Check a condition on a function
情况CheckCondition()

Note: to run a test on a simple condition, we recommend that you use the following syntax:

根据Value
情况10,那么跟踪10
情况10小于*小于20,那么跟踪"Included between 10 and 20"
情况大于30,那么跟踪"Greater than 30"
结束

OR keyword

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整数型2
根据Sub
情况1或者2,那么信息"case 1 or 2"
情况3,那么信息"case 3"
其他情况,那么信息"other case"
结束

to do:

Sub整数型2
根据Sub
情况12,那么信息"case 1 or 2"
情况3,那么信息"case 3"
其他情况,那么信息"other case"
结束

OTHER CASE keyword

其他情况 must be the last statement used in the conditional SWITCH statement.

18版本和更高版本
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. The caption of each option is automatically added in line comment.

Some examples:

  • Code for a radio button that returns an integer: typing "SWITCH RADIO_Title" in the code editor displays:
  • Code for a radio button that returns a value: typing "SWITCH RADIO_TodaysMenu" in the code editor displays:
18新版本
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. The caption of each option is automatically added in line comment.

Some examples:

  • Code for a radio button that returns an integer: typing "SWITCH RADIO_Title" in the code editor displays:
  • Code for a radio button 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. The caption of each option is automatically added in line comment.

Some examples:

  • Code for a radio button that returns an integer: typing "SWITCH RADIO_Title" in the code editor displays:
  • Code for a radio button that returns a value: typing "SWITCH RADIO_TodaysMenu" in the code editor displays: