首页 > lang > select 
 en fr de es it nl pl pt pt_BR mk sq ca hu cs tr ar fa id vi ko ja ru zh eo
前一个  下一个  编辑  重命名  撤销  搜索  管理  
文档  
警告! 该页面未翻译。  参见英文版 
SELECT
SELECT [ CASE ] Expression
  [ CASE Expression [ TO Expression #2 ] [ , ... ]     ... ]
  [ CASE Expression [ TO Expression #2 ] [ , ... ]     ... ]
  [ { CASE ELSE | DEFAULT }     ... ]
END SELECT

Selects an expression to compare, and execute the code enclosed in the corresponding matching CASE statement.

If no CASE statement matches, the DEFAULT or CASE ELSE statement is executed.

A CASE statement is a list of single values or interval of two values separated by the TO keyword.

Example

' You want to check the random function of a die.
' So you repeat the random function a thousand times
' and you count, how many times 1, 2, 3, 4, 5 or 6
' have been thrown.

DIM x AS Integer
DIM w AS Integer
DIM a AS Integer
DIM b AS Integer
DIM c AS Integer
DIM d AS Integer
DIM e AS Integer
DIM f AS Integer

FOR x = 1 TO 1000

  w = Int(Rnd(6) + 1)

  SELECT CASE w
    CASE 1
      a = a + 1
    CASE 2
      b = b + 1
    CASE 3
      c = c + 1
    CASE 4
      d = d + 1
    CASE 5
      e = e + 1
    CASE 6
      f = f + 1
    CASE ELSE
      PRINT "This is impossible!"
  END SELECT

NEXT

PRINT a, b, c, d, e, f

参见

Test Control Structures & Functions