Dim yf(1 To 10) As Integer, v(1 To 10) As Integer, b(1 To 10) As Integer
Private Sub Command1_Click()
Dim n As Integer, i As Integer, j As Integer, t As Integer
List1.AddItem "船只编号" + " " + "载重量" + " " + "运费单价" List2.AddItem "船只编号"
For i = 1 To 10 '对船只进行编号
b(i) = i
Next i
'随机生成10艘船的运费单价,数值在100到200之间,代码略
For i = 1 To 10 '随机生成10艘船载重量,载重量均不相同
v(i) = 15 + Int(Rnd() * 16)
For j = 1 To i - 1
If v(i) = v(j) Then : Exit For
Next j
Next i
For i = 1 To 9
For j = 10 To i + 1 Step -1
If Then
t = b(j): b(j) = b(j - 1): b(j - 1) = t
End If
Next j
Next i
'在list1中输出10艘船的编号、载重量、运费单价,代码略
End Sub
Private Sub Command2_Click()
Dim n As Integer, k As Integer
Dim sum As Long
n = Val(Text1.Text): sum = 0 k = 1
Do While n > 0
If n >= v(b(k)) Then
Else
sum = sum + n * yf(b(k))
End If
List2.AddItem Str(b(k)) n = n - v(b(k))
k = k + 1
Loop
Text2.Text = Str(sum)
End Sub