Related Demand and Information Click here to view.
Implement method with VB code
Quote: None, parts: None
Design: Add a CommandButton in the lower right corner of Form1, name the name of Command1, and the form of the AutoRaw property is set to True
Form file 1: Form1
Option expedition
Private MBOM As Collection 'This is the collection of the entrance private mbomreturn as collection' This is a collection of exports, unreachabiliated private mbomreturnlast as collection 'This is the collection of exports, after processing
Private sub addbomrecord () 'here to the original content in the database in MBOM, for easy, I don't want to connect the database' to write directly to the record, if necessary, you will connect directly to the database, analyze the 'code in it, Then write records in 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 submmand1_click ()
DIM I AS INTEGERDIM M AS CBOMVALUE
'Calculation
'Note the following two new instances must be placed in getBomlist, which also has the effect of emptying the existing data, otherwise the error' is saved after the first run, and the data is not cleared. And the next operation is based on the existing basis, so the data is wrong.
SET MBOMRETURN = New CollectionSet MBOMRETURNLAST = New Collection
Call getbomlist
After calculation, MBOMRETURNLAST returned to the final result if mbomreturnlast.count <0 the msgbox "no record!", Vbinformation Vbokonly, "BOM table calculation" EXIT SUBELSE
'Print list of lists in the form 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 IEND IND IN
End Sub
Private sub flow_load ()
'New instance of the form call, then load data
Set MBOM = New Collection
AddBomRecord
End Sub
'********************************************************** ************** '*' * The following is the code for calculating the calculation section, pay attention to the processing in Collection '*' *************** ******************************************************
Private Sub GetBomList () Dim mBomTop As Collection 'here save top finished products Dim i As Integer Dim j As Integer Dim m As cBomReturnValue Dim mLast As cBomValue Dim bFind As Boolean Set mBomTop = New Collection' top loading finished products LoadBomTop mBomTop ' Decision of the top product for the lower level for i = 1 to mbomtop.count 'The last parameter is 1, representing a unit of finitexTBOM (MbOMtop.Item (i), MbOMtop.Item (i), "1") Next i 'finally enabled Mbomreturn, which has been initially formed.' The resulting expression is calculated, the result is returned to MBOMRETURNLAST, Note: MBOMRETURNLAST Add to CBOMVALUE content for i = 1 to mbomReturn.count 'Processing the final result If you do not find the same AssBom and Bompoint in Collection, add one, if you have discovered, just quantity plus SET M = MBOMRETURN (i) 'Find if it is added bFIND = false for j = 1 to mbomreturnLast.count SET MLAST = MBOMRETURNLAST (J) IF Trim (Mlast.Assbom) = Trim (M.Assbom) And Trim (Mlast.Bompoint) = TRIM (M.Bompoint) Then 'If you find the same, add relevant digital mlast.quantity = M Last.quantity CalceXpression (M.EXPIRESSION) BFIND = true end if next jixd = false then 'If did not find set mlast = new cbomvalue mlast.ssbom = trim (m.ss) mlast.bompoint = trim (M.Bompoint ) Mlast.quantity = CALCEXPIPRESSION (Trim (m.expression)) MBOMRETURNLAST.ADD MLAST END IF NEXT I 'All Operation End Sub
Private subloadbomtop (Byref Bomtop As Collection "is loaded into the top-level product and returns to BOMTOP 'ie created in GetBomlist in the stored process @BOMTOP DIM I AS INTEGER DIM J AS INTEGER DIM N AS INTEGER DIM Bmark as boolean 'This is just an identifier indicating whether non-top DIM BMARKADD AS BOOLLEAN' is found to determine if it has been added to BOMTOP 'judgment method. If Assoc is not in Bompoint, it is the top Dim Sbomassbom As String for. i = 1 to MBOM.COUNT SBMASSBOM = TRIM (Mbom.Item (i) .assbom) 'Re-loop bmark = false for j = 1 to mbom.count if sbomassbom = trim (Mbom.Item (j) .bompoint) THEN Bmark = true end if next jiff = false then 'If there is no identical, BOMTOP is added to' joining before joining whether it is added for n = 1 to bomtop.count if bomtop.Item (n) = sbomassbom Then BMARKADD = TRUE END IF NEXT N if BmarkAdd = false then 'If not added, join BOMTOP.ADD SBMASSBOM END IF END I END SUB
'GetBomTrueList stored procedure with VB described Private Sub CalcNextBom (sAssBom As String, sAssPoint As String, sExp As String) Dim dQuan As Double Dim sExpression As String Dim sPoint As String Dim BomTop As String' Create a cursor Dim mBomPoint As point_cursor at Collection Set Mbompoint = New Collection 'Loading the related collection Call loadNextPoint (Mbompoint, SassPoint)' After loading, the judgment is the class-level semi-finished product, if not, recursive once this function, if yes, add to MBOMRETURN DIM I as cbomreturnvalue for i = 1 to mbompoint.count 'Judging whether it is a class if isdetailpoint (Trim (mbompoint.Item (i) .bompoint) = True Then' If it is a fine level, add CBOMRETURNVALUE Set mBomReturnValue = New cBomReturnValue mBomReturnValue.AssBom = Trim (sAssBom) mBomReturnValue.BomPoint = Trim (mBomPoint.Item (i) .BomPoint) 'expression construct mBomReturnValue.Expression = sExp & "*" & Trim (CStr (mBomPoint.Item ( i) .quantity)) MbomreturnValue.quantity = MBOMP Oint.item (i) .quantity 'joins MBOMRETURN.ADD MBOMRETURNVALUE ELSE' If it is not a definition, recursively, pay attention to the first parameter of incoming, always top BOM, only identifically Call CalcNextbom (Sassbom, Trim (MbMMPOINT.ITEM (i) .bompoint, SEXP & "*" & TRIM (cstr (Mbompoint.Item (i) .quient)) endness i end subsprivate subloadnextpoint (byref Bompoint As Collection, Byval Pointname As String ) 'Select Distinct Point, SL from TE where assbom = @pointname in the cursor in getBomtruelist
DIM I AS INTEGER DIM J AS INTEGER DIM BMARK AS BOOLEAN DIM MPOINTVALUE AS CPOINTVALUE for I = 1 to MBOM.COUNT BMARK = false if Trim (Mbom.Item (i) .ssbom) = TRIM (POINTNAME) THEN 'Judgment has been added For j = 1 to bompoint.count if trim (bompoint.item (j) .bompoint) = trim (Mbom.Item (i) .bompoint) and bompoint.Item (j) .quantity = MBOM.Item (i) .quantity Then bMark = True End If Next j If bMark = False Then 'indicates no added Set mPointValue = New cPointValue mPointValue.BomPoint = Trim (mBom.Item (i) .BomPoint) mPointValue.Quantity = mBom.Item (i) .Quantity BomPoint .Add mpointvalue end ifend if Next i
End Sub
Private function isdetailpoint (byval pointname as string) as boolean 'judgment is a bottom-level half-finished product
'Judging that PointName is not in the ASSBOM item of MBOM, DIM I as integer for i = 1 to MBOM.COUNT IF TRIM (Mbom.Item (i) .ssbom) = Trim (PointName) Then' If found, return directly FALSE, and exit the function isdetailpoint = false exit function end if next i 'If it is not found here, then it is definitely isDetailPoint = TrueEnd Function
Public Function Calcexpression (strexp as string) AS Double 'computing expression in the process, pay attention, only multiplication
DIM Sitemexp () AS STRING
DIM DRETURNVALUE AS Doubledim IIndex as in
SiteMexp = SPLIT (Trim (strexp), "*")
IF ubound (sitemex) <0 Then Calcexpression = 0ELSE
dReturnValue = 1 For iIndex = 0 To UBound (sItemExp) If Trim (sItemExp (iIndex)) = "" Then sItemExp (iIndex) = 0 End If dReturnValue = dReturnValue * CDbl (sItemExp (iIndex)) Next iIndex CalcExpression = dReturnValueEnd If
END FUNCTION
Class module 1: Class name: CBOMRETURNVALUE
Option expedition
'Holding property values of local variables Private mvarAssBom As String' local copy Private mvarBomPoint As String 'local copy Private mvarQuantity As Double' local copy Private mvarExpression As String 'local copy Public Property Let Expression (ByVal vData As String)' to an attribute assigned a value Use, located on the left of the assignment statement. 'Syntax: x.expression = 5 mvarexpression = vdatand property
Public property Get Expression () AS String 'When retrieving attribute values, the right side of the assignment statement is located. 'Syntax: debug.print x.expression expression = mvarexpressionnd Property
Public property let Quantity (BYVAL VDATA AS DOUBLE) 'is used to assign the value to the left side of the assignment statement. 'Syntax: x.quantity = 5 mvarquantity = vDataEnd Property
Public property get quantity () AS Double 'When retrieving attribute values, the right side of the assignment statement is located. 'Syntax: debug.print x.quantity quantity = mvarquantityEnd Property
Public Property Let Bompoint 'When you assign a value to the property, it is located on the left side of the assignment statement. 'Syntax: x.bompoint = 5 mvarbompoint = vDataEnd Property
Public property get bompoint () AS string 'When retrieving attribute values, the right side of the assignment statement is located. 'Syntax: debug.print x.bompoint bompoint = mvarbompointenstribr
Public Property Let Assoc (BYVAL VDATA AS STRING "is used to assign the value to the left side of the assignment statement. 'Syntax: x.assbom = 5 mvarassbom = vdataend property
Public property get asseb () AS string 'When retrieving attribute values, the right side of the assignment statement is located. 'Syntax: debug.print x.assbom assbom = mvarassbomend property module 2: Class Name: CBomvalue
Option expedition
'Holding property values of local variables Private mvarAssBom As String' local copy Private mvarBomPoint As String 'local copy Private mvarQuantity As Double' local copy Public Property Let Quantity (ByVal vData As Double) 'when the property is assigned values using located assignment statement left. 'Syntax: x.quantity = 5 mvarquantity = vDataEnd Property
Public property get quantity () AS Double 'When retrieving attribute values, the right side of the assignment statement is located. 'Syntax: debug.print x.quantity quantity = mvarquantityEnd Property
Public Property Let Bompoint 'When you assign a value to the property, it is located on the left side of the assignment statement. 'Syntax: x.bompoint = 5 mvarbompoint = vDataEnd Property
Public property get bompoint () AS string 'When retrieving attribute values, the right side of the assignment statement is located. 'Syntax: debug.print x.bompoint bompoint = mvarbompointenstribr
Public Property Let Assoc (BYVAL VDATA AS STRING "is used to assign the value to the left side of the assignment statement. 'Syntax: x.assbom = 5 mvarassbom = vdataend property
Public property get asseb () AS string 'When retrieving attribute values, the right side of the assignment statement is located. 'Syntax: debug.print x.assbom assbom = mvarasbomend property
Class module three: Class Name: CPointValue
Option expedition
'Local Variables of the Property Value Private MVARBMMPOINT AS STRING' Local Copy Private Mvarquantity AS Double 'Local Copy Public Property Let Quantity (Byval VDATA AS Double) The value is used to assign the value to the left side of the assignment statement. 'Syntax: x.quantity = 5 mvarquantity = vDataEnd Property
Public property get quantity () AS Double 'When retrieving attribute values, the right side of the assignment statement is located. 'Syntax: debug.print x.quantity quantity = mvarquantityEnd Property
Public Property Let Bompoint 'When you assign a value to the property, it is located on the left side of the assignment statement. 'Syntax: x.bompoint = 5 mvarbompoint = vdataEnd PropertyPublic property Get Bompoint () AS String' When retrieving attribute values, the right side of the assignment statement is located. 'Syntax: debug.print x.bompoint bompoint = mvarbompointensN
After adding, you can print directly in the form.