请高手看看这段vb代码有什么错误,应该怎么办?

来源:百度知道 编辑:UC知道 时间:2024/06/07 17:32:07
Private Sub Command1_Click()
Dim score As Double
passn = 0: Sum = 0: n = 0
For i = 1 To 50
score = InputBox("请输入分数", "成绩统计")
If score < 0 Then
Exit For
Else
If score >= 60 Then passn = passn + 1
n = n + 1
Sum = Sum + score
End If
Next i

End Sub

Private Sub Command2_Click()
Text1.Text = Str$(n)
Text2.Text = Str$(passn)
Text3.Text = Str$(Sum / n)
End Sub

Dim n, passn, sum
Private Sub Command1_Click()
Dim score As Double
passn = 0: sum = 0: n = 0
For i = 1 To 50
score = InputBox("请输入分数", "成绩统计")
If score < 0 Then
Exit For
Else
If score >= 60 Then passn = passn + 1
n = n + 1
sum = sum + score
End If
Next i

End Sub

Private Sub Command2_Click()
Text1.Text = Str$(n)
Text2.Text = Str$(passn)
Text3.Text = Str$(sum / n)
End Sub

没有定义全局变量 导致按钮2里变量为0