1 Reply Latest reply on Aug 14, 2018 11:47 AM by Guy Edkins

    EPDM API for BoM Extraction in VBA

    Guy Edkins

      varval.png

       

              Dim BOM As IEdmBomView3

            

              Set BOM = eFile.GetComputedBOM("Standard Roll Up BOM", -1, ConfigName, EdmBomFlag.EdmBf_ShowSelected)

        

             ' Call BOM.SaveToCSV("c:\temp\guy.txt", True)

           

              '----------------------------FILE.CREATE("C:\TEMP\BOM.TXT")

              Dim fso As New FileSystemObject

              Dim sw As TextStream

              Set sw = fso.CreateTextFile("c:\temp\" & AssyName & ".txt")

       

       

              '-----------------------------GET COLUMN HEADERS

              Dim columns() As EdmBomColumn

              BOM.GetColumns columns

              Dim header As String

              header = "LEVEL" & vbTab

              Dim column As EdmBomColumn

              For i = 0 To UBound(columns)

                  header = header & columns(i).mbsCaption & vbTab

              Next

              sw.writeline (header)

             ' -----------------------------Bom.READ EACH BOM ROW

        

          Dim varVal As String

          Dim rows() As Variant

          Dim row As IEdmBomCell

          Dim rowstring As String

           Call BOM.GetRows(rows)

              For p = 0 To UBound(rows)

                  Set row = rows(p)

                      rowstring = row.GetTreeLevel & vbTab

                      varVal = ""

       

                    For i = 0 To UBound(columns)

                          column = columns(i)

                          Call row.GetVar(column.mlColumnID, column.meType, varVal, Nothing, "", True)  <= varval never returns a value even though columns are being incremented, see above image showing variable watches.

                          rowstring = rowstring & varVal & vbTab

                          Debug.Print rowstring

                      Next

                      '-----------------------------WRITE THE ROW TO THE FILE

                     sw.writeline (rowstring)

              Next

              sw.Close

        • Re: EPDM API for BoM Extraction in VBA
          Mr Omkar Deshpande

          For both of your questions...

           

          Try Set row = rows(i) after For i = 0 To Ubound(rows) for first loop only.

           

          For second loop you may need to try Set column = columns (p)

           

           

          Consider this:

           

          Dim rows() As Variant

          Dim varVal As String

          Dim row As EdmBomCell

          BOM.GetRows rows

           

           

                  For i = 0 To UBound(rows)

                      Set row = rows(i)

                          rowString = row.GetTreeLevel & vbTab

                          Debug.Print rowString

                          varVal = ""

                          For p = 0 To UBound(columns)

                              Set column = columns(p)

                              RetVal = row.GetVar(column.mlColumnID, column.meType, varVal, Nothing, "", True)   <== . FAILS HERE AT RUNTIME WITH EXPECTED FUNCTION OR VARIABLE

                              If (varVal) <> "" Then varVal = ""

                              rowString = rowString & varVal & vbTab

                          Next

                          '-----------------------------WRITE THE ROW TO THE FILE

                         sw.writeline (rowString)

                  Next