范例:公园售票系统:
Private Sub Command1_Click()
Dim height As Double
height = CInt(Text1.Text)
If height >= 120 Then
Text2.Text = " 全票"
ElseIf height >= 100 And height < 120 Then
Text2.Text = " 半票"
Else: Text2.Text = " 免票"
End If
End Sub
用语言描述或者流程图的方式来叙述下列代码的工作流程。
1.成绩
Private Sub Command1_Click()
Dim score As Integer
Dim grade As String
score = InputBox("请输入你的成绩")
If score >= 60 Then
grade = "及格"
Else
grade = "不及格"
End If
Text1.Text = "你的成绩是:" & grade
End Sub
2.计算(有能力者选做)
Private Sub Command1_Click()
Dim i As Integer
Dim a As Integer
Dim b As Integer
Dim an As Integer
For i = 1 To 10
a = Int(Rnd * 1000 + 1)
b = Int(Rnd * 1000 + 1)
Frame1.Caption = "题目:" + CStr(a) + "+" + CStr(b)
an = InputBox("请输入正确答案")
c = a + b
If Int(an) = Int(c) Then
MsgBox "对了,你真行"
Else
MsgBox "错了,继续加油!"
End If
Next i