Crystal Reports Designer  

單行和多行 If 陳述式 (Basic 語法)

If 陳述式有兩種:單行的 If 陳述式和多行的 If 陳述式。如果在第一個 Then 之後另起一行,就使 If 陳述式成為多行 If 陳述式。否則就是單行 If 陳述式。多行 If 陳述式一定會包含 End If,單行 If 陳述式則不包含。

注意   因為可以使用行連續字元,所以單行 If 陳述式也不一定只有一行。大致而言,最好使用多行 If 陳述式,因為其配置較清楚。但在簡單的情況下,有時還是會使用單行的 If 陳述式。
Rem Single-line If example 1
Rem Same result as multi-line If example 1
If {Employee.Dept} = "Sales" Then _
   formula = {Employee.Salary} * 0.06 _
Else _
   formula = {Employee.Salary} * 0.04

此處顯示不同型式的單行 If 陳述式:

Rem Single-line If example 2
Dim per As Number, extra As Boolean
per = 2 : extra = False
'An example with no Else clause
If {Employee.Dept} = "Sales" Then per = 10
'More than 1 statement in the Then or Else part can
'be included by separating them with colons
If {Employee.Dept} = "R&D" Then _
   per = 5 : extra = True _
Else _
   per = 3

請參閱

控制結構 | If 陳述式 | Select 陳述式