圖1
例如某天的銷售清單,庫(kù)存數(shù)據(jù)如圖2所示,根據(jù)每本書(shū)的警戒1和警戒2庫(kù)存,分組后的數(shù)據(jù)如圖3所示。
圖2
圖3
Dim stock(1 To 52) As Integer '存儲(chǔ)每本書(shū)警戒1和警戒2的庫(kù)存數(shù)量
Dim num(1 To 100) As Integer '存儲(chǔ)每本書(shū)每次的銷售數(shù)量
Dim bm(1 to 26) As String '存儲(chǔ)每本書(shū)的書(shū)名編碼
Dim kc(1 To 26) As Integer '存儲(chǔ)每本書(shū)的庫(kù)存數(shù)量
Dim sell(1 To 26) As Integer,q(1 To 26) As Integer
Private Sub Form_Load()
'從數(shù)據(jù)庫(kù)讀取書(shū)目銷售清單數(shù)據(jù),顯示在list1中,分別存在數(shù)組
'stock(1),stock(2)存書(shū)名編碼A的警戒1庫(kù)存,警戒2庫(kù)存;stock(3),stock(4)存書(shū)名編碼B的警戒1庫(kù)存,警戒2庫(kù)存,依次類推,代碼略
End sub
Private Sub Command1_Click()
For i = 1 To 100 '處理100條銷售清單數(shù)據(jù)
k = Asc(bm(i)) - 64
Next i
n = 0
For i = 1 To 26 '更新庫(kù)存數(shù)據(jù)
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
'分組排序及排序后數(shù)據(jù)顯示在列表框list2中,代碼略
End Sub