根据.上述要求设计VB程序,功能如下:在窗体加载时,读取木块长度和厚度数据,并显示在列表框List1中,单击“排序”按钮实现木块排序,结果显示在列表框List2中,程序运行界面如图b所示。
Const n = 10
Dim cd(1 To n) As Single, hd(1 To n) As Single
Private Sub Form_ Load()
'通过数据库读取n根木块的长度数据存储到cd数组,厚度数据存储到hd数组,并将数据显示在列表框List1中,代码略
End Sub
Private Sub Com1_Click()
Dim L As Integer, R As Integer
Dim min As Integer
Dim i As Integer, j As Integer
Dim t1 As Single, t2 As Single
For i=1 To n-1
min=i
For j=i+1 To n
If Then min= j
Next j
R=min
'实现区间内木块的整体翻转
Do While L<R
t1 = cd(L): cd(L) = cd(R): cd(R) = t1
t2 = hd(L): hd(L) = hd(R): hd(R) = t2
L=L+1
Loop
Next i
List2. AddItem"长度(cm)"+""+"厚度(cm)"
For i =1 To n
List2. AddItem Str(cd(i)) +"" + Str(hd(i))
Next i
End Sub