vb冒泡成绩排序

用vb冒泡编程做成绩统计:用5个textbox输入5门成绩在list上输出输入的成绩(一行输出)点击command排序后输出PrivateSubTxt1_KeyPress... 用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)) + "" + Str(e(n)) + "" + Str(f(n)) + "" + Str(g(n)) + "" + Str(h(n)))
Txt3.Text = "": Txt3.SetFocus
End If
End Sub

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

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

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

我编的输入部分,但是运行出来很奇怪
展开
 我来答
刀成朝1
2009-05-02 · TA获得超过1334个赞
知道大有可为答主
回答量:763
采纳率:0%
帮助的人:717万
展开全部
'你这样做输入很累,用数组控件又要好一些。建议你用一个 命令按钮 添加一个成绩组,添加之前先检查控件是否为空或者是否合法,一次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 + 1
End If
Txt3.Text = "": Txt4.SetFocus
End If
End Sub

Private Sub Txt4_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
Txt4.Text = "": Txt5.SetFocus
End If
End Sub

Private Sub Txt5_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
Lst1.AddItem (Str(n) + "," + Str(d(n)) + "," + Str(e(n)) + "," + Str(f(n)) + "," + Str(g(n)) + "," + Str(h(n)))
Txt5.Text = "": Txt1.SetFocus
End If
End Sub
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式