Z
zhongding
Unregistered / Unconfirmed
GUEST, unregistred user!
Private Sub cmdAssign_Click()
Dim arrTotal() As Double '所有线路ID
Dim arrFjj1() As Double '一号分拣机
Dim arrFjj2() As Double '二号分拣机
Dim arrFjj3() As Double '三号分拣机
Dim i As Long, j As Long, k As Long '各整型变量
Dim dblFjj1 As Double '一号分拣机总量
Dim dblFjj2 As Double '二号分拣机总量
Dim dblFjj3 As Double '三号分拣机总量
Dim bolChange As Boolean '是否变换
Dim bolIs As Boolean '是否分配成功
Dim dblAverage As Double '三台机平均量
Dim intBase As Double '相差基数
Dim intIndex As Integer '数组索引值
Dim intValue As Double '数组值
'On Error GoTo Err
'所有选择重新取数据
If Option1.Value = True Then Option1_Click
If Option2.Value = True Then Option2_Click
If Option3.Value = True Then Option3_Click
If Option4.Value = True Then Option4_Click
If Option5.Value = True Then Option5_Click
'如果没有数据,退出
If lstRoute.ListCount <= 0 Then Exit Sub
ReDim arrTotal(lstRoute.ListCount, 2) As Double
ReDim arrFjj1(lstRoute.ListCount, 2) As Double
ReDim arrFjj2(lstRoute.ListCount, 2) As Double
ReDim arrFjj3(lstRoute.ListCount, 2) As Double
'取所有线路信息入线路数组
For i = 0 To lstRoute.ListCount - 1
arrTotal(i, 0) = i + 1
arrTotal(i, 1) = CDbl(Mid(lstRoute.List(i), InStr(lstRoute.List(i), "--" + 2))
Next
'粗略分配;1,2,3;6,5,4方式分配
bolChange = False
j = 0
For i = 0 To UBound(arrTotal) - 1 Step 3
If bolChange = True Then
bolChange = False
arrFjj1(j, 0) = arrTotal(i, 0)
arrFjj1(j, 1) = arrTotal(i, 1)
If (i + 1) < UBound(arrTotal) Then
arrFjj2(j, 0) = arrTotal(i + 1, 0)
arrFjj2(j, 1) = arrTotal(i + 1, 1)
End If
If (i + 2) < UBound(arrTotal) Then
arrFjj3(j, 0) = arrTotal(i + 2, 0)
arrFjj3(j, 1) = arrTotal(i + 2, 1)
End If
Else
bolChange = True
arrFjj3(j, 0) = arrTotal(i, 0)
arrFjj3(j, 1) = arrTotal(i, 1)
If (i + 1) < UBound(arrTotal) Then
arrFjj2(j, 0) = arrTotal(i + 1, 0)
arrFjj2(j, 1) = arrTotal(i + 1, 1)
End If
If (i + 2) < UBound(arrTotal) Then
arrFjj1(j, 0) = arrTotal(i + 2, 0)
arrFjj1(j, 1) = arrTotal(i + 2, 1)
End If
End If
j = j + 1
Next i
'求三台机的总量
For i = 0 To UBound(arrFjj1) - 1
dblFjj1 = dblFjj1 + arrFjj1(i, 1)
Next i
For i = 0 To UBound(arrFjj2) - 1
dblFjj2 = dblFjj2 + arrFjj2(i, 1)
Next i
For i = 0 To UBound(arrFjj3) - 1
dblFjj3 = dblFjj3 + arrFjj3(i, 1)
Next i
dblAverage = (dblFjj1 + dblFjj2 + dblFjj3) / 3
intBase = 100
bolIs = True
'详细分配
Do While bolIs
bolChange = False
If Abs(dblFjj1 - dblAverage) > intBase Then '判断一号机是否需要详细分配
If (dblFjj1 - dblAverage) > intBase Then '如果一号机量多时
If (dblFjj2 - dblAverage) < (-1 * intBase) Then '如果是二号机量少时
For i = 0 To UBound(arrFjj1) - 1 '逐步判断一号机每一条线路
If arrFjj1(i, 1) = 0 Then Exit For
For j = 0 To UBound(arrFjj2) - 1 '逐步判断二号机每一条线路
If arrFjj2(j, 1) = 0 Then Exit For
If arrFjj1(i, 1) > arrFjj2(j, 1) Then
intIndex = arrFjj1(i, 0)
intValue = arrFjj1(i, 1)
arrFjj1(i, 0) = arrFjj2(j, 0)
arrFjj1(i, 1) = arrFjj2(j, 1)
arrFjj2(j, 0) = intIndex
arrFjj2(j, 1) = intValue
dblFjj1 = 0
For k = 0 To UBound(arrFjj1) - 1
dblFjj1 = dblFjj1 + arrFjj1(k, 1)
Next k
dblFjj2 = 0
For k = 0 To UBound(arrFjj2) - 1
dblFjj2 = dblFjj2 + arrFjj2(k, 1)
Next k
If Abs(dblFjj1 - dblAverage) <= intBase Then
bolChange = True
Exit For
End If
End If
Next j
If bolChange = True Then
Exit For
End If
Next i
Else
If (dblFjj3 - dblAverage) < (-1 * intBase) Then
For i = 0 To UBound(arrFjj1) - 1
If arrFjj1(i, 1) = 0 Then Exit For
For j = 0 To UBound(arrFjj3) - 1
If arrFjj2(j, 1) = 0 Then Exit For
If arrFjj1(i, 1) > arrFjj3(j, 1) Then
intIndex = arrFjj1(i, 0)
intValue = arrFjj1(i, 1)
arrFjj1(i, 0) = arrFjj3(j, 0)
arrFjj1(i, 1) = arrFjj3(j, 1)
arrFjj3(j, 0) = intIndex
arrFjj3(j, 1) = intValue
dblFjj1 = 0
For k = 0 To UBound(arrFjj1) - 1
dblFjj1 = dblFjj1 + arrFjj1(k, 1)
Next k
dblFjj3 = 0
For k = 0 To UBound(arrFjj3) - 1
dblFjj3 = dblFjj3 + arrFjj3(k, 1)
Next k
If Abs(dblFjj3 - dblAverage) <= intBase Then
bolChange = True
Exit For
End If
End If
Next j
If bolChange = True Then
bolIs = False
Exit For
End If
Next i
Else
bolIs = False
End If
End If
Else
If (dblFjj2 - dblAverage) > intBase Then
For i = 0 To UBound(arrFjj1) - 1
If arrFjj1(i, 1) = 0 Then Exit For
For j = 0 To UBound(arrFjj2) - 1
If arrFjj3(j, 1) = 0 Then Exit For
If arrFjj1(i, 1) < arrFjj2(j, 1) Then
intIndex = arrFjj1(i, 0)
intValue = arrFjj1(i, 1)
arrFjj1(i, 0) = arrFjj2(j, 0)
arrFjj1(i, 1) = arrFjj2(j, 1)
arrFjj2(j, 0) = intIndex
arrFjj2(j, 1) = intValue
dblFjj1 = 0
For k = 0 To UBound(arrFjj1) - 1
dblFjj1 = dblFjj1 + arrFjj1(k, 1)
Next k
dblFjj2 = 0
For k = 0 To UBound(arrFjj2) - 1
dblFjj2 = dblFjj2 + arrFjj2(k, 1)
Next k
If Abs(dblFjj1 - dblAverage) <= intBase Then
Exit For
End If
End If
Next j
If bolChange = True Then
Exit For
End If
Next i
Else
If (dblFjj3 - dblAverage) > intBase Then
For i = 0 To UBound(arrFjj1) - 1
If arrFjj1(i, 1) = 0 Then Exit For
For j = 0 To UBound(arrFjj3) - 1
If arrFjj3(j, 1) = 0 Then Exit For
If arrFjj1(i, 1) < arrFjj3(j, 1) Then
intIndex = arrFjj1(i, 0)
intValue = arrFjj1(i, 1)
arrFjj1(i, 0) = arrFjj3(j, 0)
arrFjj1(i, 1) = arrFjj3(j, 1)
arrFjj3(j, 0) = intIndex
arrFjj3(j, 1) = intValue
dblFjj1 = 0
For k = 0 To UBound(arrFjj1) - 1
dblFjj1 = dblFjj1 + arrFjj1(k, 1)
Next k
dblFjj3 = 0
For k = 0 To UBound(arrFjj3) - 1
dblFjj3 = dblFjj3 + arrFjj3(k, 1)
Next k
If Abs(dblFjj3 - dblAverage) <= intBase Then
bolChange = True
Exit For
End If
End If
Next j
If bolChange = True Then
bolIs = False
Exit For
End If
Next i
End If
End If
End If
End If
If bolIs = False Then Exit Do
bolChange = False
If (dblFjj2 - dblAverage) > intBase Then
If (dblFjj3 - dblAverage) < (-1 * intBase) Then
For i = 0 To UBound(arrFjj2) - 1
If arrFjj2(i, 1) = 0 Then Exit For
For j = 0 To UBound(arrFjj3) - 1
If arrFjj3(j, 1) = 0 Then Exit For
If arrFjj2(i, 1) > arrFjj3(j, 1) Then
intIndex = arrFjj2(i, 0)
intValue = arrFjj2(i, 1)
arrFjj2(i, 0) = arrFjj3(j, 0)
arrFjj2(i, 1) = arrFjj3(j, 1)
arrFjj3(j, 0) = intIndex
arrFjj3(j, 1) = intValue
dblFjj2 = 0
For k = 0 To UBound(arrFjj2) - 1
dblFjj2 = dblFjj2 + arrFjj2(k, 1)
Next k
dblFjj3 = 0
For k = 0 To UBound(arrFjj3) - 1
dblFjj3 = dblFjj3 + arrFjj3(k, 1)
Next k
If Abs(dblFjj2 - dblAverage) <= intBase Then
bolIs = False
bolChange = True
Exit For
End If
End If
Next j
If bolChange = True Then
Exit For
End If
Next i
End If
ElseIf (dblFjj2 - dblAverage) < (-1 * intBase) Then
If (dblFjj3 - dblAverage) > intBase Then
For i = 0 To UBound(arrFjj2) - 1
If arrFjj2(i, 1) = 0 Then Exit For
For j = 0 To UBound(arrFjj3) - 1
If arrFjj3(j, 1) = 0 Then Exit For
If arrFjj2(i, 1) < arrFjj3(j, 1) Then
intIndex = arrFjj2(i, 0)
intValue = arrFjj2(i, 1)
arrFjj2(i, 0) = arrFjj3(j, 0)
arrFjj2(i, 1) = arrFjj3(j, 1)
arrFjj3(j, 0) = intIndex
arrFjj3(j, 1) = intValue
dblFjj2 = 0
For k = 0 To UBound(arrFjj2) - 1
dblFjj2 = dblFjj2 + arrFjj2(k, 1)
Next k
dblFjj3 = 0
For k = 0 To UBound(arrFjj3) - 1
dblFjj3 = dblFjj3 + arrFjj3(k, 1)
Next k
If Abs(dblFjj2 - dblAverage) <= intBase Then
bolIs = False
bolChange = True
Exit For
End If
End If
Next j
If bolChange = True Then
Exit For
End If
Next i
End If
Else
bolIs = False
End If
intBase = intBase + 100
Loop
For i = 0 To UBound(arrFjj1) - 1
If arrFjj1(i, 0) > 0 Then
lst1.AddItem lstRoute.List(arrFjj1(i, 0) - 1)
lblRoute1.Caption = CInt(lblRoute1.Caption) + 1
End If
Next i
lbl1.Caption = "一号分拣机:" & dblFjj1
For i = 0 To UBound(arrFjj2) - 1
If arrFjj2(i, 0) > 0 Then
lst2.AddItem lstRoute.List(arrFjj2(i, 0) - 1)
lblRoute2.Caption = CInt(lblRoute2.Caption) + 1
End If
Next i
lbl2.Caption = "二号分拣机:" & dblFjj2
For i = 0 To UBound(arrFjj3) - 1
If arrFjj3(i, 0) > 0 Then
lst3.AddItem lstRoute.List(arrFjj3(i, 0) - 1)
lblRoute3.Caption = CInt(lblRoute3.Caption) + 1
End If
Next i
lbl3.Caption = "三号分拣机:" & dblFjj3
'lstRoute.Clear
Exit Sub
Err:
MsgBox Err.Description
End Sub
Dim arrTotal() As Double '所有线路ID
Dim arrFjj1() As Double '一号分拣机
Dim arrFjj2() As Double '二号分拣机
Dim arrFjj3() As Double '三号分拣机
Dim i As Long, j As Long, k As Long '各整型变量
Dim dblFjj1 As Double '一号分拣机总量
Dim dblFjj2 As Double '二号分拣机总量
Dim dblFjj3 As Double '三号分拣机总量
Dim bolChange As Boolean '是否变换
Dim bolIs As Boolean '是否分配成功
Dim dblAverage As Double '三台机平均量
Dim intBase As Double '相差基数
Dim intIndex As Integer '数组索引值
Dim intValue As Double '数组值
'On Error GoTo Err
'所有选择重新取数据
If Option1.Value = True Then Option1_Click
If Option2.Value = True Then Option2_Click
If Option3.Value = True Then Option3_Click
If Option4.Value = True Then Option4_Click
If Option5.Value = True Then Option5_Click
'如果没有数据,退出
If lstRoute.ListCount <= 0 Then Exit Sub
ReDim arrTotal(lstRoute.ListCount, 2) As Double
ReDim arrFjj1(lstRoute.ListCount, 2) As Double
ReDim arrFjj2(lstRoute.ListCount, 2) As Double
ReDim arrFjj3(lstRoute.ListCount, 2) As Double
'取所有线路信息入线路数组
For i = 0 To lstRoute.ListCount - 1
arrTotal(i, 0) = i + 1
arrTotal(i, 1) = CDbl(Mid(lstRoute.List(i), InStr(lstRoute.List(i), "--" + 2))
Next
'粗略分配;1,2,3;6,5,4方式分配
bolChange = False
j = 0
For i = 0 To UBound(arrTotal) - 1 Step 3
If bolChange = True Then
bolChange = False
arrFjj1(j, 0) = arrTotal(i, 0)
arrFjj1(j, 1) = arrTotal(i, 1)
If (i + 1) < UBound(arrTotal) Then
arrFjj2(j, 0) = arrTotal(i + 1, 0)
arrFjj2(j, 1) = arrTotal(i + 1, 1)
End If
If (i + 2) < UBound(arrTotal) Then
arrFjj3(j, 0) = arrTotal(i + 2, 0)
arrFjj3(j, 1) = arrTotal(i + 2, 1)
End If
Else
bolChange = True
arrFjj3(j, 0) = arrTotal(i, 0)
arrFjj3(j, 1) = arrTotal(i, 1)
If (i + 1) < UBound(arrTotal) Then
arrFjj2(j, 0) = arrTotal(i + 1, 0)
arrFjj2(j, 1) = arrTotal(i + 1, 1)
End If
If (i + 2) < UBound(arrTotal) Then
arrFjj1(j, 0) = arrTotal(i + 2, 0)
arrFjj1(j, 1) = arrTotal(i + 2, 1)
End If
End If
j = j + 1
Next i
'求三台机的总量
For i = 0 To UBound(arrFjj1) - 1
dblFjj1 = dblFjj1 + arrFjj1(i, 1)
Next i
For i = 0 To UBound(arrFjj2) - 1
dblFjj2 = dblFjj2 + arrFjj2(i, 1)
Next i
For i = 0 To UBound(arrFjj3) - 1
dblFjj3 = dblFjj3 + arrFjj3(i, 1)
Next i
dblAverage = (dblFjj1 + dblFjj2 + dblFjj3) / 3
intBase = 100
bolIs = True
'详细分配
Do While bolIs
bolChange = False
If Abs(dblFjj1 - dblAverage) > intBase Then '判断一号机是否需要详细分配
If (dblFjj1 - dblAverage) > intBase Then '如果一号机量多时
If (dblFjj2 - dblAverage) < (-1 * intBase) Then '如果是二号机量少时
For i = 0 To UBound(arrFjj1) - 1 '逐步判断一号机每一条线路
If arrFjj1(i, 1) = 0 Then Exit For
For j = 0 To UBound(arrFjj2) - 1 '逐步判断二号机每一条线路
If arrFjj2(j, 1) = 0 Then Exit For
If arrFjj1(i, 1) > arrFjj2(j, 1) Then
intIndex = arrFjj1(i, 0)
intValue = arrFjj1(i, 1)
arrFjj1(i, 0) = arrFjj2(j, 0)
arrFjj1(i, 1) = arrFjj2(j, 1)
arrFjj2(j, 0) = intIndex
arrFjj2(j, 1) = intValue
dblFjj1 = 0
For k = 0 To UBound(arrFjj1) - 1
dblFjj1 = dblFjj1 + arrFjj1(k, 1)
Next k
dblFjj2 = 0
For k = 0 To UBound(arrFjj2) - 1
dblFjj2 = dblFjj2 + arrFjj2(k, 1)
Next k
If Abs(dblFjj1 - dblAverage) <= intBase Then
bolChange = True
Exit For
End If
End If
Next j
If bolChange = True Then
Exit For
End If
Next i
Else
If (dblFjj3 - dblAverage) < (-1 * intBase) Then
For i = 0 To UBound(arrFjj1) - 1
If arrFjj1(i, 1) = 0 Then Exit For
For j = 0 To UBound(arrFjj3) - 1
If arrFjj2(j, 1) = 0 Then Exit For
If arrFjj1(i, 1) > arrFjj3(j, 1) Then
intIndex = arrFjj1(i, 0)
intValue = arrFjj1(i, 1)
arrFjj1(i, 0) = arrFjj3(j, 0)
arrFjj1(i, 1) = arrFjj3(j, 1)
arrFjj3(j, 0) = intIndex
arrFjj3(j, 1) = intValue
dblFjj1 = 0
For k = 0 To UBound(arrFjj1) - 1
dblFjj1 = dblFjj1 + arrFjj1(k, 1)
Next k
dblFjj3 = 0
For k = 0 To UBound(arrFjj3) - 1
dblFjj3 = dblFjj3 + arrFjj3(k, 1)
Next k
If Abs(dblFjj3 - dblAverage) <= intBase Then
bolChange = True
Exit For
End If
End If
Next j
If bolChange = True Then
bolIs = False
Exit For
End If
Next i
Else
bolIs = False
End If
End If
Else
If (dblFjj2 - dblAverage) > intBase Then
For i = 0 To UBound(arrFjj1) - 1
If arrFjj1(i, 1) = 0 Then Exit For
For j = 0 To UBound(arrFjj2) - 1
If arrFjj3(j, 1) = 0 Then Exit For
If arrFjj1(i, 1) < arrFjj2(j, 1) Then
intIndex = arrFjj1(i, 0)
intValue = arrFjj1(i, 1)
arrFjj1(i, 0) = arrFjj2(j, 0)
arrFjj1(i, 1) = arrFjj2(j, 1)
arrFjj2(j, 0) = intIndex
arrFjj2(j, 1) = intValue
dblFjj1 = 0
For k = 0 To UBound(arrFjj1) - 1
dblFjj1 = dblFjj1 + arrFjj1(k, 1)
Next k
dblFjj2 = 0
For k = 0 To UBound(arrFjj2) - 1
dblFjj2 = dblFjj2 + arrFjj2(k, 1)
Next k
If Abs(dblFjj1 - dblAverage) <= intBase Then
Exit For
End If
End If
Next j
If bolChange = True Then
Exit For
End If
Next i
Else
If (dblFjj3 - dblAverage) > intBase Then
For i = 0 To UBound(arrFjj1) - 1
If arrFjj1(i, 1) = 0 Then Exit For
For j = 0 To UBound(arrFjj3) - 1
If arrFjj3(j, 1) = 0 Then Exit For
If arrFjj1(i, 1) < arrFjj3(j, 1) Then
intIndex = arrFjj1(i, 0)
intValue = arrFjj1(i, 1)
arrFjj1(i, 0) = arrFjj3(j, 0)
arrFjj1(i, 1) = arrFjj3(j, 1)
arrFjj3(j, 0) = intIndex
arrFjj3(j, 1) = intValue
dblFjj1 = 0
For k = 0 To UBound(arrFjj1) - 1
dblFjj1 = dblFjj1 + arrFjj1(k, 1)
Next k
dblFjj3 = 0
For k = 0 To UBound(arrFjj3) - 1
dblFjj3 = dblFjj3 + arrFjj3(k, 1)
Next k
If Abs(dblFjj3 - dblAverage) <= intBase Then
bolChange = True
Exit For
End If
End If
Next j
If bolChange = True Then
bolIs = False
Exit For
End If
Next i
End If
End If
End If
End If
If bolIs = False Then Exit Do
bolChange = False
If (dblFjj2 - dblAverage) > intBase Then
If (dblFjj3 - dblAverage) < (-1 * intBase) Then
For i = 0 To UBound(arrFjj2) - 1
If arrFjj2(i, 1) = 0 Then Exit For
For j = 0 To UBound(arrFjj3) - 1
If arrFjj3(j, 1) = 0 Then Exit For
If arrFjj2(i, 1) > arrFjj3(j, 1) Then
intIndex = arrFjj2(i, 0)
intValue = arrFjj2(i, 1)
arrFjj2(i, 0) = arrFjj3(j, 0)
arrFjj2(i, 1) = arrFjj3(j, 1)
arrFjj3(j, 0) = intIndex
arrFjj3(j, 1) = intValue
dblFjj2 = 0
For k = 0 To UBound(arrFjj2) - 1
dblFjj2 = dblFjj2 + arrFjj2(k, 1)
Next k
dblFjj3 = 0
For k = 0 To UBound(arrFjj3) - 1
dblFjj3 = dblFjj3 + arrFjj3(k, 1)
Next k
If Abs(dblFjj2 - dblAverage) <= intBase Then
bolIs = False
bolChange = True
Exit For
End If
End If
Next j
If bolChange = True Then
Exit For
End If
Next i
End If
ElseIf (dblFjj2 - dblAverage) < (-1 * intBase) Then
If (dblFjj3 - dblAverage) > intBase Then
For i = 0 To UBound(arrFjj2) - 1
If arrFjj2(i, 1) = 0 Then Exit For
For j = 0 To UBound(arrFjj3) - 1
If arrFjj3(j, 1) = 0 Then Exit For
If arrFjj2(i, 1) < arrFjj3(j, 1) Then
intIndex = arrFjj2(i, 0)
intValue = arrFjj2(i, 1)
arrFjj2(i, 0) = arrFjj3(j, 0)
arrFjj2(i, 1) = arrFjj3(j, 1)
arrFjj3(j, 0) = intIndex
arrFjj3(j, 1) = intValue
dblFjj2 = 0
For k = 0 To UBound(arrFjj2) - 1
dblFjj2 = dblFjj2 + arrFjj2(k, 1)
Next k
dblFjj3 = 0
For k = 0 To UBound(arrFjj3) - 1
dblFjj3 = dblFjj3 + arrFjj3(k, 1)
Next k
If Abs(dblFjj2 - dblAverage) <= intBase Then
bolIs = False
bolChange = True
Exit For
End If
End If
Next j
If bolChange = True Then
Exit For
End If
Next i
End If
Else
bolIs = False
End If
intBase = intBase + 100
Loop
For i = 0 To UBound(arrFjj1) - 1
If arrFjj1(i, 0) > 0 Then
lst1.AddItem lstRoute.List(arrFjj1(i, 0) - 1)
lblRoute1.Caption = CInt(lblRoute1.Caption) + 1
End If
Next i
lbl1.Caption = "一号分拣机:" & dblFjj1
For i = 0 To UBound(arrFjj2) - 1
If arrFjj2(i, 0) > 0 Then
lst2.AddItem lstRoute.List(arrFjj2(i, 0) - 1)
lblRoute2.Caption = CInt(lblRoute2.Caption) + 1
End If
Next i
lbl2.Caption = "二号分拣机:" & dblFjj2
For i = 0 To UBound(arrFjj3) - 1
If arrFjj3(i, 0) > 0 Then
lst3.AddItem lstRoute.List(arrFjj3(i, 0) - 1)
lblRoute3.Caption = CInt(lblRoute3.Caption) + 1
End If
Next i
lbl3.Caption = "三号分拣机:" & dblFjj3
'lstRoute.Clear
Exit Sub
Err:
MsgBox Err.Description
End Sub