爸爸们!!VB小题不会做
利用列表框完成以下功能:①随机产生10个[10,20]区间的整数,并添加到列表框。
②使用冒泡法将列表框数据由小到大排序。
Option Explicit Const MAXSIZE = 10 Dim d(MAXSIZE + 1) As Integer, n As Integer Private Sub Command1_Click() Dim i As Integer, j As Integer n = Val(txtSize.Text) If n <= 0 Or n > MAXSIZE Then txtSize = "数据个数必须大于0!" Exit Sub End If Randomize lstUnsorted.Clear For i = 1 To n j = Int(11 * Rnd)+20 lstUnsorted.AddItem Str$(j) d(i) = j Next Command2.Enabled = True End Sub Private Sub Command2_Click() '冒泡 Dim i, j, TEMP, NextElement lstSorted.Clear For i = 1 To n - 1 For j = n To i Step -1 If d(j) < d(j - 1) Then TEMP = d(j) d(j) = d(j - 1) d(j - 1) = TEMP End If Next Next For i = 1 To n lstSorted.AddItem d(i) Next End Sub
[此贴子已经被作者于2016-4-20 14:09编辑过]