vb冒泡成绩排序

来源:百度知道 编辑:UC知道 时间:2024/05/24 13:33:28
用vb冒泡编程做成绩统计:
用5个textbox输入5门成绩
在list上输出输入的成绩(一行输出)
点击command排序后输出
Private Sub Txt1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
n = n + 1: d(n) = Val(Txt1.Text)
Lst1.AddItem (Str(n) + "" + Str(d(n)) + "" + Str(e(n)) + "" + Str(f(n)) + "" + Str(g(n)) + "" + Str(h(n)))
Txt1.Text = "": Txt1.SetFocus
End If
End Sub

Private Sub Txt2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
n = n + 1: e(n) = Val(Txt2.Text)
Lst1.AddItem (Str(n) + "" + Str(d(n)) + "" + Str(e(n)) + "" + Str(f(n)) + "" + Str(g(n)) + "" + Str(h(n)))
Txt2.Text = "": Txt2.SetFocus
End If
End Sub

Private Sub Txt3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
n = n + 1: f(n) = Val(Txt3.Text)
Lst1.AddItem (Str(n) + "" + Str(d(n)) + "

'你这样做输入很累,用数组控件又要好一些。建议你用一个 命令按钮 添加一个成绩组,添加之前先检查控件是否为空或者是否合法,一次Lst1.AddItem
'稍微帮你改一下
Private Sub Txt1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If d(n) <> 0 And e(n) <> 0 And f(n) <> 0 And g(n) <> 0 And h(n) <> 0 Then '如果有 0 分的就……把初始值改为-1吧
n = n + 1
End If
d(n) = Val(Txt1.Text) '
Txt1.Text = "": Txt2.SetFocus
End If
End Sub

Private Sub Txt2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If d(n) <> 0 And e(n) <> 0 And f(n) <> 0 And g(n) <> 0 And h(n) <> 0 Then '如果有 0 分的就……把初始值改为-1吧
n = n + 1
End If
Txt2.Text = "": Txt3.SetFocus
End If
End Sub

Private Sub Txt3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If d(n) <> 0 And e(n) <> 0 And f(n) <> 0 And g(n) <> 0 And h(n) <> 0 Then '如果有 0 分的就……把初始值改为-1吧
n = n