求解VB题目 关于任何设置数值范围

来源:百度知道 编辑:UC知道 时间:2024/05/25 08:12:11
输入的成绩a(i) 需要在5到10之间 下面的程序怎么改呢

Private Sub ordernum(a() As Integer)
Dim i As Integer, j As Integer, p As Integer
Dim t As Single, n As Integer, m As Integer
n = LBound(a)
m = UBound(a)
For i = n To m - 1
p = i
For j = i + 1 To m
If a(p) < a(j) Then p = j
Next j
t = a(i): a(i) = a(p): a(p) = t
Next i
End Sub
Private Sub command1_click()
Dim a(1 To 3) As Integer
For i = 1 To 3
a(i) = Val(InputBox("Enter " & "a(" & i & ")="))
Next i
Call ordernum(a)
Print "名次", "成绩"
For i = 1 To 3
Print i, a(i)
Next i
End Sub

调试通过
Private Sub ordernum(a() As Integer)
Dim i As Integer, j As Integer, p As Integer
Dim t As Single, n As Integer, m As Integer
n = LBound(a)
m = UBound(a)
For i = n To m - 1
p = i
For j = i + 1 To m
If a(p) < a(j) Then p = j
Next j
t = a(i): a(i) = a(p): a(p) = t
Next i
End Sub
Private Sub command1_click()
Dim a(1 To 3) As Integer
For i = 1 To 3
a(i) = Val(InputBox("Enter " & "a(" & i & ")="))
If Not (a(i) >= 5 And a(i) <= 10) Then
MsgBox "输入大小为5-10,请重新输入第 " & i & " 个成绩"
i = i - 1
End If
Next i
Call ordernum(a)
Print "名次", "成绩"
For i = 1 To 3
Print i, a(i)
Next i
End Sub