图1
例如某天的销售清单,库存数据如图2所示,根据每本书的警戒1和警戒2库存,分组后的数据如图3所示。
图2
图3
Dim stock(1 To 52) As Integer '存储每本书警戒1和警戒2的库存数量
Dim num(1 To 100) As Integer '存储每本书每次的销售数量
Dim bm(1 to 26) As String '存储每本书的书名编码
Dim kc(1 To 26) As Integer '存储每本书的库存数量
Dim sell(1 To 26) As Integer,q(1 To 26) As Integer
Private Sub Form_Load()
'从数据库读取书目销售清单数据,显示在list1中,分别存在数组
'stock(1),stock(2)存书名编码A的警戒1库存,警戒2库存;stock(3),stock(4)存书名编码B的警戒1库存,警戒2库存,依次类推,代码略
End sub
Private Sub Command1_Click()
For i = 1 To 100 '处理100条销售清单数据
k = Asc(bm(i)) - 64
Next i
n = 0
For i = 1 To 26 '更新库存数据
If sell(i) > 0 Then
n = n + 1
kc(i) = kc(i) - sell(i)
End If
Next i
head = 0: tail = n + 1: j = 1
Do While j < tail
r = kc(q(j))
If r <= stock(2 * q(j) - 1) Then
head = head + 1
If Then t = q(head): q(head) = q(j): q(j) = t
j = j + 1
ElseIf r > stock(2 * q(j)) Then
tail = tail - 1
t = q(j): q(j) = q(tail): q(tail) = t
Else
j = j + 1
End If
Loop
'分组排序及排序后数据显示在列表框list2中,代码略
End Sub