2011年计算机等级考试二级VB考点及习题(4)
分类: 计算机
时间: 2023-05-28 11:53:08
作者: 全国等级考试资料网
例如:1、if 语句:
Private Sub Form_Click()
Dim x As Integer, y As Integer
Dim z As Single
x = 0.2
y = 1
If (x >= 1) Then
z = Log(x)
ElseIf x >= 0 And x < 1 And y >= 0 Then
z = 2 * x - y
Else
z = Exp(x + y)
End If
Print "z=" + Str(z)
End Sub
结果: z=-1
2、Select Case语句
Private Sub Form_Click()
Dim ch As String, i As Integer
ch = "c"
Select Case ch
Case "A", "a"
i = 1
Case "B", "b"
i = 2
Case "C", "c"
i = 3
Case "D", "d"
i = 4
Case Else
i = 5
End Select
Print "运行结果" + Ucase(ch) + Str(i)
End Sub
结果:运行结果C3
② 循环结构
1、For------Next (循环次数的计算)
特例: