vb 分支语句

来源:百度知道 编辑:UC知道 时间:2024/07/06 16:18:17

on s1,s2,s3... goto

select is 条件

case i then...
case j then....
end select

Visual Basic 过程能够测试条件式,然后根据测试结果执行不同的操作。Visual Basic 支持的判定结构有:

If...Then

If...Then...Else

Select Case
If...Then
用 If...Then 结构有条件地执行一个或多个语句。单行语法和多行块语法都可以使用:

If condition Then statement

If condition Then
statements

End If

Condition 通常是比较式,但它可以是任何计算数值的表达式。Visual Basic 将这个值解释为 True 或 False:一个为零的数值为 False,而任何非零数值都被看作 True。若 condition 为 True,则 Visual Basic 执行 Then 关键字后面的所有 statements。可以使用单行或多行语法有条件地执行一个语句(下面两个例子等价):

If anyDate < Now Then anyDate = Now

If anyDate < Now Then
anyDate = Now
End If

注意:If...Then 的单行格式不用 End If 语句。如果 condition 为 True 时要执行多行代码,则必须使用多行块 If...Then...End If 语法。

If anyDate < Now Then
anyDate = Now
Timer1.Enabled = False '定时器控制失效。
End If

If...Then...Else