程式代碼:
Private Sub Command1_Click()
If IsNumeric(Text1.Text) Then
Select Case CInt(Text1.Text)
Case Is >= 85
Label2.Caption = "成績:" & "優秀"
Case 70 To 84
Label2.Caption = "成績:" & "良好"
Case 60, 61, 62, 63, 64, 65, 66, 67, 68, 69
Label2.Caption = "成績:" & "及格"
Case Else
Label2.Caption = "成績:" & "差"
End Select
End If
End Sub
程式小結:
1、IsNumeric()函數含義“是數字”,即判斷是否為數字;
2、CInt():強制轉換為整型,小數部分四舍五入;
3、Case分支語句後面可以使用的三種形式:“Is”,“To”,“,”。