IBM Lotus Symphony
|
定义一个或多个仅当给定条件为 True 时才会执行的语句块。
If condition=true Then Statement block [ElseIf condition=true Then] Statement block [Else] Statement block EndIf Instead of Else If you can write ElseIf, instead of End If you can write EndIf.
If...Then 语句根据给定的条件来执行程序块。当 Lotus® Symphony™ Basic 遇到 If 语句时,会测试其条件。如果条件为 True,将执行所有后续语句直到遇到下一个 Else 或 ElseIf 语句。如果条件为 False,并且后面有 ElseIf 语句,那么 Lotus Symphony Basic 测试下一个条件,如果该条件为 True,请执行后面的语句。如果仍为 False,程序将继续测试下一步 ElseIf 或 Else 语句。仅当先前测试的条件都不为 True 时,才会执行 Else 后面的语句。对所有条件进行求值并执行相应语句后,程序将继续执行 EndIf 后面的语句。
If...Then 语句可以多层嵌套。
Else 和 elseIf 语句是可选语句。
![]() |
您可以使用 GoTo 和 GoSub 跳出 If...Then 块,但不能跳入 If...Then 结构。 |
以下示例可用于输入产品的截止日期并确定产品是否已超过截止日期。
Sub ExampleIfThenDate
Dim sDate as String
Dim sToday as String
sDate = InputBox("Enter the expiration date (MM.DD.YYYY) ")
sDate = Right$(sDate, 4) + Mid$(sDate, 4, 2) + Left$(sDate, 2)
sToday = Date$
sToday = Right$(sToday, 4) + Mid$(sToday, 4, 2) + Left$(sToday, 2)
If sDate < sToday Then
MsgBox "The expiration date has passed"
ElseIf sDate > sToday Then
MsgBox "The expiration date has not yet passed"
Else
MsgBox "The expiration date is today"
Loop Until sFile = ""
End Sub