代码介绍
Select
' Select 选择语句结构
Sub Select_Sub()
Dim Score As Integer
Score = 6
Select Case Score
Case Is >= 90
MsgBox "优秀"
Case Is >= 80
MsgBox "良好"
Case Is >= 70
MsgBox "普通"
Case Is >= 60
MsgBox "及格"
Case Else
MsgBox "不及格"
End Select
End Sub
If
' If判断语句结构
Sub If_Sub()
Dim Score As Integer
Score = 556
If Score >= 90 Then
MsgBox "优秀"
ElseIf Score >= 80 Then
MsgBox "良好"
ElseIf Score >= 70 Then
MsgBox "普通"
ElseIf Score >= 60 Then
MsgBox "及格"
Else
MsgBox "不及格"
End If
End Sub
For
' For 循环语句
Sub For_Sub()
Dim Num As Integer, Sum As Integer
' 步长为1
Sum = 0
For Num = 1 To 10
Sum = Sum + Num
Next Num
MsgBox Sum
' 步长为2:1,3,5,7,9
Sum = 0
For Num = 1 To 10 Step 2
Sum = Sum + Num
Next Num
MsgBox Sum
' 步长为2,且大于10中断:1,3,5,7,9
Sum = 0
For Num = 1 To 100 Step 2
If Num > 10 Then
Exit For
End If
Sum = Sum + Num
Next Num
MsgBox Sum
End Sub
' For 循环嵌套语句
Sub For2_Sub()
Dim Row As Integer, Col As Integer
For Row = 1 To 2
For Col = 1 To 3
MsgBox "当前是:" & Row & "行," & Col & "列"
Next Col
Next Row
End Sub
Do While
' Do While 循环语句
Sub DoWhile_Sub()
Dim Cnt As Integer
Cnt = 1
Do While Cnt <= 5
MsgBox "当前循环位置:" & Cnt
Cnt = Cnt + 1
Loop
End Sub
Do Until
' Until 循环语句
Sub Until_Sub()
Dim Cnt As Integer
Cnt = 1
Do Until Cnt >= 5
MsgBox "当前循环位置:" & Cnt
Cnt = Cnt + 1
Loop
End Sub
关注
笔者 - jxd
微信公众号搜索 “码农总动员” 或 微信扫描下方二维码,了解更多你不知道的XX,O(∩_∩)O