Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'This is just an example program to show how to generate a UN/EDIFACT ORDERS S93A EDI file
        'in VB.NET with Framework EDI component

        Dim oEdiDoc As ediDocument
        Dim oSchema As ediSchema
        Dim oSchemas As ediSchemas
        Dim oInterchange As ediInterchange
        Dim oGroup As ediGroup
        Dim oTransactionset As ediTransactionSet
        Dim oSegment As ediDataSegment

        Dim sPath As String = AppDomain.CurrentDomain.BaseDirectory
        Dim sEdiFile As String = "ORDERS.TXT"
        Dim sSefFile As String = "ORDERS_S93A.SEF"

        Cursor = Cursors.WaitCursor

        'CREATES OEDIDOC OBJECT
        ediDocument.Set(oEdiDoc, New ediDocument)

        'THIS MAKES CERTAIN THAT FREDI ONLY USES THE SEF FILE PROVIDED, AND THAT IT DOES 
        'NOT USE ITS BUILT-IN STANDARD REFERENCE TABLE TO GENERATE THE EDI FILE.
        ediSchemas.Set(oSchemas, oEdiDoc.GetSchemas)
        oSchemas.EnableStandardReference = False

        'ENABLES FORWARD WRITE, AND INCREASES BUFFER I/O TO IMPROVE PERFORMANCE
        oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardWrite
        oEdiDoc.Property(DocumentPropertyIDConstants.Property_DocumentBufferIO) = 2000

        'LOADS THE SEF FILE
        ediSchema.Set(oSchema, oEdiDoc.LoadSchema(sPath & sSefFile, 0))

        'SET TERMINATORS
        oEdiDoc.SegmentTerminator = "'"
        oEdiDoc.ElementTerminator = "+"
        oEdiDoc.CompositeTerminator = ":"
        oEdiDoc.ReleaseIndicator = "?"

        'enable option to create the UNA segment from defined terminators above
        oEdiDoc.Option(DocumentOptionIDConstants.OptDocument_ServiceSegment) = 1

        'CREATES THE UNB SEGMENT
        ediInterchange.Set(oInterchange, oEdiDoc.CreateInterchange("UN", "S93A"))
        ediDataSegment.Set(oSegment, oInterchange.GetDataSegmentHeader)
        oSegment.DataElementValue(1, 1) = "UNOB"    'Syntax identifier
        oSegment.DataElementValue(1, 2) = "1"    'Syntax version number
        oSegment.DataElementValue(2, 1) = "003897733"    'Interchange sender identification
        oSegment.DataElementValue(2, 2) = "1"    'Partner identification code qualifier
        oSegment.DataElementValue(2, 3) = "MFGB"    'Interchange sender internal identification
        oSegment.DataElementValue(3, 1) = "PARTNER ID"    'Recipient identification
        oSegment.DataElementValue(3, 2) = "ZZZ"    'Partner identification code qualifier
        oSegment.DataElementValue(3, 3) = "ROUTING ADDR"    'Routing address
        oSegment.DataElementValue(4, 1) = "970101"    'Date
        oSegment.DataElementValue(4, 2) = "1230"    'Time
        oSegment.DataElementValue(5) = "00000000000001"     'Interchange control reference
        oSegment.DataElementValue(7) = "ORDERS"     'Application reference
        oSegment.DataElementValue(11) = "1"     'Test indicator

        'CREATES THE UNH SEGMENT
        ediTransactionSet.Set(oTransactionset, oInterchange.CreateTransactionSet("ORDERS"))
        ediDataSegment.Set(oSegment, oTransactionset.GetDataSegmentHeader)
        oSegment.DataElementValue(1) = "0001"     'Message reference number
        oSegment.DataElementValue(2, 1) = "ORDERS"    'Message type identifier
        oSegment.DataElementValue(2, 2) = "S"    'Message version number
        oSegment.DataElementValue(2, 3) = "93A"    'Message release number
        oSegment.DataElementValue(2, 4) = "UN"    'Controlling agency

        'BGM - BEGINNING OF MESSAGE
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("BGM"))
        oSegment.DataElementValue(1, 1) = "221"    'Document/message name, coded
        oSegment.DataElementValue(2) = "M1Q512345"     'Document/message number
        oSegment.DataElementValue(3) = "9"     'Message function, coded

        'DTM - DATE/TIME/PERIOD
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("DTM"))
        oSegment.DataElementValue(1, 1) = "4"    'Date/time/period qualifier
        oSegment.DataElementValue(1, 2) = "20000101"    'Date/time/period
        oSegment.DataElementValue(1, 3) = "102"    'Date/time/period format qualifier

        'FTX - FREE TEXT
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("FTX"))
        oSegment.DataElementValue(1) = "PUR"     'Text subject qualifier
        oSegment.DataElementValue(2) = "3"     'Text function, coded
        oSegment.DataElementValue(4, 1) = "PURCHASE ORDER BEFORE LINE ITEM"    'Free text

        'RFF - REFERENCE - Creates the first instance of the RFF group
        'creates RFF segment in group RFF
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("RFF\RFF"))
        oSegment.DataElementValue(1, 1) = "CT"    'Reference qualifier
        oSegment.DataElementValue(1, 2) = txtContractNo.Text     'Reference number

        'RFF - REFERENCE - Creates the second instance of the RFF group.  Note that the loop instance counter (2) in the syntax is not necessary when cursor type is set to ForwardWrite.
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("RFF(2)\RFF"))
        oSegment.DataElementValue(1, 1) = "CR"    'Reference qualifier
        oSegment.DataElementValue(1, 2) = txtCustRefNo.Text     'Reference number

        'NAD - NAME AND ADDRESS - Creates the first instance of the NAD group.  This is the Seller information group 
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("NAD\NAD"))
        oSegment.DataElementValue(1) = "SE"     'Party qualifier
        oSegment.DataElementValue(2, 1) = "10025392"    'Party identification
        oSegment.DataElementValue(2, 3) = "92"    'Code list responsible agency, coded
        oSegment.DataElementValue(4, 1) = "SUPPLIER NAME"    'Party name

        'CTA - CONTACT INFORMATION of the Seller
        'Creates CTA segment in group CTA nested in NAD group
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("NAD\CTA\CTA"))
        oSegment.DataElementValue(1) = "SR"     'Contact function, coded
        oSegment.DataElementValue(2, 2) = "Steve"    'Department or employee

        'NAD - NAME AND ADDRESS - Creates the second instance of the NAD group.  This is the Bill-To information group 
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("NAD(2)\NAD"))
        oSegment.DataElementValue(1) = "BT"     'Party qualifier
        oSegment.DataElementValue(2, 1) = "B2"    'Party identification
        oSegment.DataElementValue(2, 3) = "92"    'Code list responsible agency, coded
        oSegment.DataElementValue(4, 1) = "DEFG COMPUTER CORP"    'Party name
        oSegment.DataElementValue(5, 1) = "P.O.BOX 123456"    'Street and number/p.o. box
        oSegment.DataElementValue(6) = "HOUSTON"     'City name
        oSegment.DataElementValue(7) = "TX"     'Country sub-entity identification
        oSegment.DataElementValue(8) = "22333"     'Postcode identification
        oSegment.DataElementValue(9) = "US"     'Country, coded

        'NAD - NAME AND ADDRESS - Creates the third instance of the NAD group.  This is the Buyer information group 
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("NAD(3)\NAD"))
        oSegment.DataElementValue(1) = "BY"     'Party qualifier
        oSegment.DataElementValue(2, 1) = "MFUS"    'Party identification
        oSegment.DataElementValue(2, 3) = "92"    'Code list responsible agency, coded
        oSegment.DataElementValue(4, 1) = "DEFG COMPUTER CORP."    'Party name

        'CTA - CONTACT INFORMATION of the Buyer
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("NAD(3)\CTA\CTA"))
        oSegment.DataElementValue(1) = "PD"     'Contact function, coded
        oSegment.DataElementValue(2, 2) = "C POST - FULTON"    'Department or employee

        'NAD - NAME AND ADDRESS - Creates the fourth instance of the NAD group.  This is the Ship-To information group 
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("NAD(4)\NAD"))
        oSegment.DataElementValue(1) = "ST"     'Party qualifier
        oSegment.DataElementValue(2, 1) = "CM6"    'Party identification
        oSegment.DataElementValue(2, 3) = "92"    'Code list responsible agency, coded
        oSegment.DataElementValue(4, 1) = "DEFG COMPUTER CORP."    'Party name
        oSegment.DataElementValue(5, 1) = "20555 SH 249"    'Street and number/p.o. box
        oSegment.DataElementValue(6) = "HOUSTON"     'City name
        oSegment.DataElementValue(7) = "TX"     'Country sub-entity identification
        oSegment.DataElementValue(8) = "77070"     'Postcode identification
        oSegment.DataElementValue(9) = "US"     'Country, coded

        'Creates TAX segment in group TAX
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("TAX\TAX"))
        oSegment.DataElementValue(1) = "9"     'Duty/tax/fee function qualifier
        oSegment.DataElementValue(7) = "3-00105-5135-3"     'Party tax identification number

        'CUX - CURRENCIES
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("CUX\CUX"))
        oSegment.DataElementValue(1, 1) = "2"    'Currency details qualifier
        oSegment.DataElementValue(1, 2) = "US"    'Currency, coded
        oSegment.DataElementValue(1, 3) = "9"    'Currency qualifier

        'PAT - PAYMENT TERMS BASIS
        'Creates first instance of PAT group
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("PAT\PAT"))
        oSegment.DataElementValue(1) = "1"     'Payment terms type qualifier
        oSegment.DataElementValue(3, 1) = "1"    'Payment time reference, coded
        oSegment.DataElementValue(3, 2) = "1"    'Time relation, coded
        oSegment.DataElementValue(3, 3) = "D"    'Type of period, coded
        oSegment.DataElementValue(3, 4) = "45"    'Number of periods

        'PAT - PAYMENT TERMS BASIS
        'Creates second instance of PAT group
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("PAT(2)\PAT"))
        oSegment.DataElementValue(1) = "22"     'Payment terms type qualifier
        oSegment.DataElementValue(3, 1) = "1"    'Payment time reference, coded
        oSegment.DataElementValue(3, 2) = "1"    'Time relation, coded
        oSegment.DataElementValue(3, 3) = "D"    'Type of period, coded
        oSegment.DataElementValue(3, 4) = "30"    'Number of periods

        'PCD - PERCENTAGE DETAILS
        'creates PCD segment in second intance of PAT group
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("PAT(2)\PCD"))
        oSegment.DataElementValue(1, 1) = "12"    'Percentage qualifier
        oSegment.DataElementValue(1, 2) = "2"    'Percentage

        'TDT - TRANSPORT INFORMATION
        'creates the TDT segment in TDT group
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("TDT\TDT"))
        oSegment.DataElementValue(1) = "20"     'Transport stage qualifier
        oSegment.DataElementValue(5, 4) = "AIRBORNE"    'Carrier name

        'LOC - PLACE/LOCATION IDENTIFICATION
        'creates LOC segment in LOC group nested in TDT group
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("TDT\LOC\LOC"))
        oSegment.DataElementValue(1) = "16"     'Place/location qualifier
        oSegment.DataElementValue(2, 1) = "DEFG DOCK"    'Place/location identification

        'TOD - TERMS OF DELIVERY OR TRANSPORT
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("TOD\TOD"))
        oSegment.DataElementValue(1) = "2"     'Terms of delivery or transport function, coded
        oSegment.DataElementValue(2) = "NS"     'Transport charges method of payment, coded
        oSegment.DataElementValue(3, 4) = "ORIGIN COLLECT"    'Terms of delivery or transport

        'LIN - LINE ITEM
        'creates the LIN segment in LIN group
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LIN\LIN"))
        oSegment.DataElementValue(1) = "1"     'Line item number
        oSegment.DataElementValue(3, 1) = "130918-001"    'Item number
        oSegment.DataElementValue(3, 2) = "SN"    'Item number type, coded

        'PIA - ADDITIONAL PRODUCT ID
        'creates PIA segment in LIN group
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LIN\PIA"))
        oSegment.DataElementValue(1) = "1"     'Product id. function qualifier
        oSegment.DataElementValue(2, 1) = "AA"    'Item number
        oSegment.DataElementValue(2, 2) = "EF"    'Item number type, coded
        oSegment.DataElementValue(3, 1) = "123456"    'Item number
        oSegment.DataElementValue(3, 2) = "VS"    'Item number type, coded

        'IMD - ITEM DESCRIPTION
        'creates IMD segment in LIN group
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LIN\IMD"))
        oSegment.DataElementValue(1) = "F"     'Item description type, coded
        oSegment.DataElementValue(2) = "8"     'Item characteristic, coded
        oSegment.DataElementValue(3, 3) = "PART DESCRIPTION INFORMATION"    'Item description

        'QTY - QUANTITY
        'creates QTY segment in LIN group
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LIN\QTY"))
        oSegment.DataElementValue(1, 1) = "21"    'Quantity qualifier
        oSegment.DataElementValue(1, 2) = "1000000"    'Quantity
        oSegment.DataElementValue(1, 3) = "PCE"    'Measure unit qualifier

        'DTM - DATE/TIME/PERIOD
        'creates DTM segment in LIN group
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LIN\DTM"))
        oSegment.DataElementValue(1, 1) = "2"    'Date/time/period qualifier
        oSegment.DataElementValue(1, 2) = "20000301"    'Date/time/period
        oSegment.DataElementValue(1, 3) = "102"    'Date/time/period format qualifier

        'FTX - FREE TEXT
        'creates FTX segment in LIN group
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LIN\FTX"))
        oSegment.DataElementValue(1) = "PUR"     'Text subject qualifier
        oSegment.DataElementValue(2) = "3"     'Text function, coded
        oSegment.DataElementValue(4, 1) = "LINE ITEM COMMENTS"    'Free text

        'PRI - PRICE DETAILS
        'creates PRI segment in PRI group nested in LIN group
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LIN\PRI\PRI"))
        oSegment.DataElementValue(1, 1) = "CAL"    'Price qualifier
        oSegment.DataElementValue(1, 2) = "50"    'Price

        'TAX - DUTY/TAX/FEE DETAILS
        'creates TAX segment in TAX group nested in LIN group
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LIN\TAX\TAX"))
        oSegment.DataElementValue(1) = "7"     'Duty/tax/fee function qualifier
        oSegment.DataElementValue(5, 4) = "100"    'Duty/tax/fee rate

        'MOA - MONETARY AMOUNT
        'creates MOA segment in TAX group nested in LIN group
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LIN\TAX\MOA"))
        oSegment.DataElementValue(1, 1) = "124"    'Monetary amount type qualifier
        oSegment.DataElementValue(1, 2) = "100"    'Monetary amount

        'UNS - SECTION CONTROL
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("UNS"))
        oSegment.DataElementValue(1) = "S"     'Section identification

        'TRAILING SEGMENTS ARE AUTOMATICALLY CREATED WHEN FREDI COMMITS (SAVES) THE EDIDOC OBJECT INTO A FILE.
        oEdiDoc.Save(sPath & sEdiFile)

        'show edi document object
        MessageBox.Show(oEdiDoc.GetEdiString)

        'DESTROYS OBJECTS
        oSegment.Dispose()
        oTransactionset.Dispose()
        oSchema.Dispose()
        oInterchange.Dispose()
        oEdiDoc.Dispose()

        Cursor = Cursors.Default

        MessageBox.Show("Done. Output = " & sPath & sEdiFile)

    End Sub
    

    Click here to download a trial version of the Framework EDI