
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
我编的输入部分,但是运行出来很奇怪 展开
用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
我编的输入部分,但是运行出来很奇怪 展开
展开全部
'你这样做输入很累,用数组控件又要好一些。建议你用一个 命令按钮 添加一个成绩组,添加之前先检查控件是否为空或者是否合法,一次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
'稍微帮你改一下
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
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询