'This is just an example program to show how to generate a UN/EDIFACT INVOIC in VB6 using Framework EDI

    Option Explicit
    Private oEdiDoc As Fredi.ediDocument
    Private oSchemas As Fredi.ediSchemas
    Private oInterchange As Fredi.ediInterchange
    Private oTransactionset As Fredi.ediTransactionSet
    Private oSegment As Fredi.ediDataSegment
    Private sSefFile As String
    Private sEdiFile As String

    Private Sub cmdGenerate_Click()
        Dim i As Integer
        Dim nCount As Integer
        Dim sPath As String
        Dim sEntity As String
        Dim nIndex As Integer
        Dim sSefFile As String
        Dim sEdiFile As String
        Dim iItemCount As Integer
    
        cmdGenerate.Enabled = False
        Me.MousePointer = vbHourglass
        sPath = App.Path & "\"
    
        sEdiFile = "INVOIC.TXT"
        sSefFile = "INVOIC_S93A.SEF"
    
        'instantiate edi document object
        Set oEdiDoc = New Fredi.ediDocument
    
        'ForwardWrite setting does not keep the created segments in memory, thus saving RAM and improving performance
        oEdiDoc.CursorType = Cursor_ForwardWrite
    
        'disable the internal standard reference library to make sure component uses the SEF provided
        Set oSchemas = oEdiDoc.GetSchemas
        oSchemas.EnableStandardReference = False
    
        'Load SEF file
        oEdiDoc.LoadSchema sPath & sSefFile, Schema_Standard_Exchange_Format
    
        'Set terminators
        oEdiDoc.SegmentTerminator = "'"
        oEdiDoc.ElementTerminator = "+"
        oEdiDoc.CompositeTerminator = ":"
        oEdiDoc.ReleaseIndicator = "?"
    
        'Create UNA segment
        oEdiDoc.Option(OptDocument_ServiceSegment) = 1
    
        'create the interchange UNB segment
        Set oInterchange = oEdiDoc.CreateInterchange("UN", "S93A")
        Set oSegment = oInterchange.GetDataSegmentHeader
        oSegment.DataElementValue(1, 1) = "UNOB"    'composite element 1, subelement 1
        oSegment.DataElementValue(1, 2) = "1"       'composite element 1, subelement 2
        oSegment.DataElementValue(2, 1) = txtPartnerID.Text     'composite element 2, subelement 1
        oSegment.DataElementValue(2, 2) = "ZZZ"                  'composite element 2, subelement 2
        oSegment.DataElementValue(3, 1) = "0038977332"          'composite element 3, subelement 1
        oSegment.DataElementValue(3, 2) = "1"                  'composite element 3, subelement 2
        oSegment.DataElementValue(3, 3) = txtSiteCode.Text      'composite element 3, subelement 3
        oSegment.DataElementValue(4, 1) = "020331"
        oSegment.DataElementValue(4, 1) = "1230"
        oSegment.DataElementValue(5) = "00000000000001"         'date element 5
        oSegment.DataElementValue(7) = "INVOIC"                 'data element 7
        oSegment.DataElementValue(11) = "1"                     'data element 11
    
        'create the message UNH segment
        Set oTransactionset = oInterchange.CreateTransactionSet("INVOIC")
        Set oSegment = oTransactionset.GetDataSegmentHeader
        oSegment.DataElementValue(1) = "0001"                   'data element 1
        oSegment.DataElementValue(2, 1) = "INVOIC"              'composite element 2, subelement 1
        oSegment.DataElementValue(2, 2) = "S"                   'composite element 2, subelement 2
        oSegment.DataElementValue(2, 3) = "93A"                 'composite element 2, subelement 3
        oSegment.DataElementValue(2, 4) = "UN"                  'composite element 2, subelement 4
    
        'create the BGM segment
        Set oSegment = oTransactionset.CreateDataSegment("BGM")
        oSegment.DataElementValue(1, 1) = "380"                 'composite element 1, subelement 1
        oSegment.DataElementValue(2) = txtInvoiceNo.Text        'data element 2
        oSegment.DataElementValue(3) = "9"                      'data element 3
    
        'create the DTM segment
        Set oSegment = oTransactionset.CreateDataSegment("DTM")
        oSegment.DataElementValue(1, 1) = "137"
        oSegment.DataElementValue(1, 2) = Format(txtInvDate.Text, "YYYYMMDD")
        oSegment.DataElementValue(1, 3) = "102"
    
        'create the RFF segment in the RFF group
        Set oSegment = oTransactionset.CreateDataSegment("RFF\RFF")
        oSegment.DataElementValue(1, 1) = "ON"
        oSegment.DataElementValue(1, 2) = txtOrderNo.Text
    
        'create the NAD segment in the NAD group
        Set oSegment = oTransactionset.CreateDataSegment("NAD\NAD")
        oSegment.DataElementValue(1) = "RE"
        oSegment.DataElementValue(2, 3) = "92"
        oSegment.DataElementValue(4, 1) = txtManufacturerName.Text
    
        'create the RFF segment in the RFF group nested in the NAD group
        Set oSegment = oTransactionset.CreateDataSegment("NAD\RFF\RFF")
        oSegment.DataElementValue(1, 1) = "VA"
        oSegment.DataElementValue(1, 2) = txtManufRef.Text
        
        'create the CTA segment in the CTA group nested in the NAD group
        Set oSegment = oTransactionset.CreateDataSegment("NAD\CTA\CTA")
        oSegment.DataElementValue(1) = "AR"
        oSegment.DataElementValue(2, 2) = txtARContact.Text
    
        'create the COM segment in the CTA group nested in the NAD group
        Set oSegment = oTransactionset.CreateDataSegment("NAD\CTA\COM")
        oSegment.DataElementValue(1, 1) = txtARTelephone.Text
        oSegment.DataElementValue(1, 2) = "TE"

        'create the NAD segment in the second instance of the NAD group
        Set oSegment = oTransactionset.CreateDataSegment("NAD(2)\NAD")
        oSegment.DataElementValue(1) = "ST"
        oSegment.DataElementValue(2, 3) = "92"
        oSegment.DataElementValue(4, 1) = txtShipToName.Text

        'create the NAD segment in the third instance of the NAD group
        Set oSegment = oTransactionset.CreateDataSegment("NAD(3)\NAD")
        oSegment.DataElementValue(1) = "BY"
        oSegment.DataElementValue(2, 3) = "92"
        oSegment.DataElementValue(4, 1) = txtBuyerName.Text

        'create the CUX segment in the CUX group
        Set oSegment = oTransactionset.CreateDataSegment("CUX\CUX")
        oSegment.DataElementValue(1, 1) = "2"
        oSegment.DataElementValue(1, 2) = "USD"
        oSegment.DataElementValue(1, 3) = "4"

        'create the ALC segment in the ALC group
        Set oSegment = oTransactionset.CreateDataSegment("ALC\ALC")
        oSegment.DataElementValue(1) = "C"
        oSegment.DataElementValue(3) = "6"
        oSegment.DataElementValue(5, 1) = "ABG"

        'create the PCD segment in the PCD group nested in the ALC group
        Set oSegment = oTransactionset.CreateDataSegment("ALC\PCD\PCD")
        oSegment.DataElementValue(1, 1) = "1"
        oSegment.DataElementValue(1, 2) = txtToolingPerc.Text

        'create the MOA segment in the MOA group nested in the ALC group
        Set oSegment = oTransactionset.CreateDataSegment("ALC\MOA\MOA")
        oSegment.DataElementValue(1, 1) = "204"
        oSegment.DataElementValue(1, 2) = txtToolingCharge.Text

        'create the LIN segment in the LIN group
        Set oSegment = oTransactionset.CreateDataSegment("LIN\LIN")
        oSegment.DataElementValue(1) = txtLineNo.Text
        oSegment.DataElementValue(3, 1) = txtBuyerPartNo.Text
        oSegment.DataElementValue(3, 2) = "SN"

        'create the LIN segment in the QTY group
        Set oSegment = oTransactionset.CreateDataSegment("LIN\QTY")
        oSegment.DataElementValue(1, 1) = "47"
        oSegment.DataElementValue(1, 2) = txtQty.Text
        oSegment.DataElementValue(1, 3) = txtMeasure.Text

        'create the PRI segment in the PRI group nested in the LIN group
        Set oSegment = oTransactionset.CreateDataSegment("LIN\PRI\PRI")
        oSegment.DataElementValue(1, 1) = "AAA"
        oSegment.DataElementValue(1, 2) = txtItemPrice.Text
        oSegment.DataElementValue(1, 3) = "CT"

        'create the UNS segment
        Set oSegment = oTransactionset.CreateDataSegment("UNS")
        oSegment.DataElementValue(1) = "S"

        'create the MOA segment in the MOA group
        Set oSegment = oTransactionset.CreateDataSegment("MOA\MOA")
        oSegment.DataElementValue(1, 1) = "77"
        oSegment.DataElementValue(1, 2) = txtTotalAmnt.Text
        oSegment.DataElementValue(1, 3) = "USD"

        'create the TAX segment in the TAX group located in area (table) 3 of the message
        Set oSegment = oTransactionset.CreateDataSegment("TAX#3\TAX")
        oSegment.DataElementValue(1) = "7"
        oSegment.DataElementValue(2, 1) = "VAT"
        oSegment.DataElementValue(5, 4) = txtTaxRate.Text
        oSegment.DataElementValue(6) = "S"

        'create the MOA segment in the TAX group located in area (table) 3 of the message
        Set oSegment = oTransactionset.CreateDataSegment("TAX#3\MOA")
        oSegment.DataElementValue(1, 1) = "176"
        oSegment.DataElementValue(1, 2) = txtTaxAmount.Text
        oSegment.DataElementValue(1, 3) = "USD"

        'save edi document object to a file
        oEdiDoc.Save sPath & sEdiFile
    
        MsgBox ("Done. Output = " & sPath & sEdiFile)
        Me.MousePointer = vbNormal
    
    End Sub
    

    Click here to download a trial version of the Framework EDI