相关需求及信息请点击这里查看。
用VB代码实现方法
引用:无,部件:无
设计:在Form1中右下角加入一个CommandButton,名称默认为Command1,窗体的AutoRedraw属性设为True
窗体文件一:Form1
Option Explicit
Private mBom As Collection '这是入口的集合
Private mBomReturn As Collection '这是出口的集合,未经处理
Private mBomReturnLast As Collection '这是出口的集合,经过处理
Private Sub AddBomRecord()
'在这里往mBom加入数据库里面的原内容,为求简便,我不想连接数据库
'直接往里面写入记录了,如果需要,你就直接连接数据库,分析一下里面的
'代码,然后再往mBom里面写入记录
'FG SA1 2.0000
'FG SA2 3.0000
'SA1 PT1 4.0000
'SA1 PT2 5.0000
'SA2 PT1 6.0000
'SA2 PT3 7.0000
Dim mBomValue As cBomValue
Set mBomValue = New cBomValue
mBomValue.AssBom = "FG"
mBomValue.BomPoint = "SA1"
mBomValue.Quantity = 2
mBom.Add mBomValue
Set mBomValue = New cBomValue
mBomValue.AssBom = "FG"
mBomValue.BomPoint = "SA2"
mBomValue.Quantity = 3
mBom.Add mBomValue
Set mBomValue = New cBomValue
mBomValue.AssBom = "SA1"
mBomValue.BomPoint = "PT1"
mBomValue.Quantity = 4
mBom.Add mBomValue
Set mBomValue = New cBomValue
mBomValue.AssBom = "SA1"
mBomValue.BomPoint = "PT2"
mBomValue.Quantity = 5
mBom.Add mBomValue
Set mBomValue = New cBomValue
mBomValue.AssBom = "SA2"
mBomValue.BomPoint = "PT1"
mBomValue.Quantity = 6
mBom.Add mBomValue
Set mBomValue = New cBomValue
mBomValue.AssBom = "SA2"
mBomValue.BomPoint = "PT3"
mBomValue.Quantity = 7
mBom.Add mBomValue
End Sub
Private Sub Command1_Click()
Dim i As Integer
Dim m As cBomValue
'进行计算
'注意以下两个新建实例,必须放置于GetBomList前,该操作也有清空现有数据的作用,否则会造成错误
'即第一次运行后保存了数据于该两个变量中,并未清除相关记录,而下一次运行则在现有的基础上再进行加操作,因此数据错误了。
Set mBomReturn = New Collection
Set mBomReturnLast = New Collection
Call GetBomList
'计算后,mBomReturnLast返回的就是最终结果
If mBomReturnLast.Count < 0 Then
MsgBox "没有记录!", vbInformation + vbOKOnly, "BOM表计算"
Exit Sub
Else
'在窗体中打印出列表的内容
Me.Cls
Print "Assbom" & vbTab & "Point" & vbTab & "Quantity"
For i = 1 To mBomReturnLast.Count
Set m = mBomReturnLast.Item(i)
Print m.AssBom & vbTab & m.BomPoint & vbTab & m.Quantity
Next i
End If
End Sub
Private Sub Form_Load()
'窗体调用处新建实例,然后再装入数据
Set mBom = New Collection
AddBomRecord
End Sub
'***************************************************************
'*
'* 以下为进行计算部分的代码,注意Collection里面的处理
'*
'***************************************************************
Private Sub GetBomList()
Dim mBomTop As Collection '这里保存了顶级产成品
Dim i As Integer
Dim j As Integer
Dim m As cBomReturnValue
Dim mLast As cBomValue
Dim bFind As Boolean
Set mBomTop