vb有关数组和循环语句的问题
制作一个从小到大的排序的程序PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.Event...
制作一个从小到大的排序的程序
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim arr(6) As Integer
arr(0) = Val(txt1.Text)
arr(1) = Val(txt2.Text)
arr(2) = Val(txt3.Text)
arr(3) = Val(txt4.Text)
arr(4) = Val(txt5.Text)
arr(5) = Val(txt6.Text)
arr(6) = Val(txt7.Text)
Dim i, j, T As Integer
For i = 0 To 5
For j = 1 To 6
If arr(i) > arr(j) Then
T = arr(i)
arr(i) = arr(j)
arr(j) = T
End If
Next
Next
txt1.Text = arr(0)
txt2.Text = arr(1)
txt3.Text = arr(2)
txt4.Text = arr(3)
txt5.Text = arr(4)
txt6.Text = arr(5)
txt7.Text = arr(6)
End Sub
End Class
启动后,不能正确排序,
请问问题出在哪,请详解!非常感谢 展开
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim arr(6) As Integer
arr(0) = Val(txt1.Text)
arr(1) = Val(txt2.Text)
arr(2) = Val(txt3.Text)
arr(3) = Val(txt4.Text)
arr(4) = Val(txt5.Text)
arr(5) = Val(txt6.Text)
arr(6) = Val(txt7.Text)
Dim i, j, T As Integer
For i = 0 To 5
For j = 1 To 6
If arr(i) > arr(j) Then
T = arr(i)
arr(i) = arr(j)
arr(j) = T
End If
Next
Next
txt1.Text = arr(0)
txt2.Text = arr(1)
txt3.Text = arr(2)
txt4.Text = arr(3)
txt5.Text = arr(4)
txt6.Text = arr(5)
txt7.Text = arr(6)
End Sub
End Class
启动后,不能正确排序,
请问问题出在哪,请详解!非常感谢 展开
1个回答
展开全部
Dim arr(6) As Integer
arr(0) = Val(txt1.Text)
arr(1) = Val(txt2.Text)
arr(2) = Val(txt3.Text)
arr(3) = Val(txt4.Text)
arr(4) = Val(txt5.Text)
arr(5) = Val(txt6.Text)
arr(6) = Val(txt7.Text)
Dim i, j, T As Integer
For i = 0 To 6 '就改了这2个FOR
For j = i + 1 To 6 '你没有遍历所有的元素,当然不能排好啦
If arr(i) > arr(j) Then
T = arr(i)
arr(i) = arr(j)
arr(j) = T
End If
Next
Next
txt1.Text = arr(0)
txt2.Text = arr(1)
txt3.Text = arr(2)
txt4.Text = arr(3)
txt5.Text = arr(4)
txt6.Text = arr(5)
txt7.Text = arr(6)
arr(0) = Val(txt1.Text)
arr(1) = Val(txt2.Text)
arr(2) = Val(txt3.Text)
arr(3) = Val(txt4.Text)
arr(4) = Val(txt5.Text)
arr(5) = Val(txt6.Text)
arr(6) = Val(txt7.Text)
Dim i, j, T As Integer
For i = 0 To 6 '就改了这2个FOR
For j = i + 1 To 6 '你没有遍历所有的元素,当然不能排好啦
If arr(i) > arr(j) Then
T = arr(i)
arr(i) = arr(j)
arr(j) = T
End If
Next
Next
txt1.Text = arr(0)
txt2.Text = arr(1)
txt3.Text = arr(2)
txt4.Text = arr(3)
txt5.Text = arr(4)
txt6.Text = arr(5)
txt7.Text = arr(6)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询