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 an EDI X12 130 Student Educational Record (Transcript)
        'in VB.NET with Framework EDI

        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 sSefFile As String = "130_4010.SEF"
        Dim sEdifile As String = "130Outbound.x12"
        Dim sPath As String = AppDomain.CurrentDomain.BaseDirectory

        'CREATES EDI DOCUMENT 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) = 200

        'SET TERMINATORS
        oEdiDoc.SegmentTerminator = "~{13:10}"
        oEdiDoc.ElementTerminator = "*"
        oEdiDoc.CompositeTerminator = "!"

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

        'CREATES THE ISA SEGMENT
        ediInterchange.Set(oInterchange, oEdiDoc.CreateInterchange("X", "004010"))
        ediDataSegment.Set(oSegment, oInterchange.GetDataSegmentHeader)
        oSegment.DataElementValue(1) = "00"     'Authorization Information Qualifier
        oSegment.DataElementValue(2) = "          "     'Authorization Information
        oSegment.DataElementValue(3) = "00"     'Security Information Qualifier
        oSegment.DataElementValue(4) = "          "     'Security Information
        oSegment.DataElementValue(5) = "ZZ"     'Interchange ID Qualifier
        oSegment.DataElementValue(6) = "SENDER ID      "     'Interchange Sender ID
        oSegment.DataElementValue(7) = "ZZ"     'Interchange ID Qualifier
        oSegment.DataElementValue(8) = "RECEIVER ID    "     'Interchange Receiver ID
        oSegment.DataElementValue(9) = "061206"     'Interchange Date
        oSegment.DataElementValue(10) = "0101"     'Interchange Time
        oSegment.DataElementValue(11) = "U"     'Interchange Control Standards Identifier
        oSegment.DataElementValue(12) = "00401"     'Interchange Control Version Number
        oSegment.DataElementValue(13) = "000000001"     'Interchange Control Number
        oSegment.DataElementValue(14) = "0"     'Acknowledgment Requested
        oSegment.DataElementValue(15) = "T"     'Usage Indicator
        oSegment.DataElementValue(16) = "!"     'Component Element Separator

        'CREATES THE GS SEGMENT
        ediGroup.Set(oGroup, oInterchange.CreateGroup("004010"))
        ediDataSegment.Set(oSegment, oGroup.GetDataSegmentHeader)
        oSegment.DataElementValue(1) = "ED"     'Functional Identifier Code
        oSegment.DataElementValue(2) = "APP SENDER"     'Application Sender's Code
        oSegment.DataElementValue(3) = "APP RECEIVER"     'Application Receiver's Code
        oSegment.DataElementValue(4) = "01010101"     'Date
        oSegment.DataElementValue(5) = "01010101"     'Time
        oSegment.DataElementValue(6) = "1"     'Group Control Number
        oSegment.DataElementValue(7) = "X"     'Responsible Agency Code
        oSegment.DataElementValue(8) = "004010"     'Version / Release / Industry Identifier Code

        'CREATES THE ST SEGMENT
        ediTransactionSet.Set(oTransactionset, oGroup.CreateTransactionSet("130"))
        ediDataSegment.Set(oSegment, oTransactionset.GetDataSegmentHeader)
        oSegment.DataElementValue(1) = "130"     'Transaction Set Identifier Code
        oSegment.DataElementValue(2) = "0001"     'Transaction Set Control Number

        'BGN - BEGINNING SEGMENT
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("BGN"))
        oSegment.DataElementValue(1) = "00"      'Transaction Set Purpose Code
        oSegment.DataElementValue(2) = "1234567"      'Reference Identification
        oSegment.DataElementValue(3) = "20050503"      'Date
        oSegment.DataElementValue(4) = "103020"      'Time
        oSegment.DataElementValue(5) = "ET"      'Time Code

        'ERP - EDUCATIONAL RECORD PURPOSE
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("ERP"))
        oSegment.DataElementValue(1) = "PS"      'Transaction Type Code
        oSegment.DataElementValue(2) = "INF"      'Status Reason Code

        'REF - REFERENCE IDENTIFICATION
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("REF"))
        oSegment.DataElementValue(1) = "SY"      'Reference Identification Qualifier
        oSegment.DataElementValue(2) = "12345679"      'Reference Identification

        'N1 - NAME Sender
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1\N1"))
        oSegment.DataElementValue(1) = "AS"      'Entity Identifier Code
        oSegment.DataElementValue(2) = "UNIVERSITY SENDER"      'Name

        'N3 - ADDRESS INFORMATION
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1\N3"))
        oSegment.DataElementValue(1) = "123 SENDER AVENUE"      'Address Information

        'N4 - GEOGRAPHIC LOCATION
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1\N4"))
        oSegment.DataElementValue(1) = "LOS ANGELES"      'City Name

        'N1 - NAME Receiver
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1(2)\N1"))
        oSegment.DataElementValue(1) = "AT"      'Entity Identifier Code
        oSegment.DataElementValue(2) = "COLLEGE RECEIVER"      'Name

        'N3 - ADDRESS INFORMATION
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1(2)\N3"))
        oSegment.DataElementValue(1) = "456 RECEIVER ST"      'Address Information

        'N4 - GEOGRAPHIC LOCATION
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1(2)\N4"))
        oSegment.DataElementValue(1) = "NEW YORK"      'City Name

        'IN1 - INDIVIDUAL IDENTIFICATION
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("IN1\IN1"))
        oSegment.DataElementValue(1) = "1"      'Entity Type Qualifier
        oSegment.DataElementValue(2) = "04"      'Name Type Code

        'IN2 - INDIVIDUAL NAME STRUCTURE COMPONENTS
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("IN1\IN2"))
        oSegment.DataElementValue(1) = "05"      'Name Component Qualifier
        oSegment.DataElementValue(2) = "SMITH"      'Name

        'IN2 - INDIVIDUAL NAME STRUCTURE COMPONENTS
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("IN1\IN2(2)"))
        oSegment.DataElementValue(1) = "02"      'Name Component Qualifier
        oSegment.DataElementValue(2) = "MARY"      'Name

        'IN2 - INDIVIDUAL NAME STRUCTURE COMPONENTS
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("IN1\IN2(3)"))
        oSegment.DataElementValue(1) = "15"      'Name Component Qualifier
        oSegment.DataElementValue(2) = "J"      'Name

        'SST - STUDENT ACADEMIC STATUS
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("SST\SST"))
        oSegment.DataElementValue(1) = "B18"      'Status Reason Code
        oSegment.DataElementValue(2) = "D8"      'Date Time Period Format Qualifier
        oSegment.DataElementValue(3) = "19871215"      'Date Time Period

        'N1 - NAME
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("SST\N1"))
        oSegment.DataElementValue(1) = "HS"      'Entity Identifier Code
        oSegment.DataElementValue(2) = "ST MARY'S HIGH SCHOOL"      'Name

        'N4 - GEOGRAPHIC LOCATION
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("SST\N4"))
        oSegment.DataElementValue(1) = "CARSON"      'City Name
        oSegment.DataElementValue(2) = "CA"      'State or Province Code

        Dim nAtvLoop As Integer
        For nAtvLoop = 1 To 2 'number of activities
            'ATV - STUDENT ACTIVITIES AND AWARDS
            ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("ATV\ATV"))
            oSegment.DataElementValue(3) = "ATHLETE OF THE YEAR 1985"      'Entity Title

            'DTP - DATE OR TIME OR PERIOD
            ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("ATV\DTP"))
            oSegment.DataElementValue(1) = "103"      'Date/Time Qualifier
            oSegment.DataElementValue(2) = "D8"      'Date Time Period Format Qualifier
            oSegment.DataElementValue(3) = "19871130"      'Date Time Period

        Next

        Dim nTstLoop As Integer
        For nTstLoop = 1 To 3    'number of tests
            'TST - TEST SCORE RECORD
            ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("TST\TST"))
            oSegment.DataElementValue(1) = "CPE"      'Educational Test or Requirement Code
            oSegment.DataElementValue(2) = "CERTIFIED PRIMARY EDU"      'Name
            oSegment.DataElementValue(3) = "D8"      'Date Time Period Format Qualifier
            oSegment.DataElementValue(4) = "19791128"      'Date Time Period
            oSegment.DataElementValue(7) = "07"      'Level of Individual, Test, or Course Code

            'SBT - SUBTEST
            ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("TST\SBT\SBT"))
            oSegment.DataElementValue(1) = "TOTAL"      'Subtest Code

            'SRE - TEST SCORES
            ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("TST\SBT\SRE"))
            oSegment.DataElementValue(1) = "3"      'Test Score Qualifier Code
            oSegment.DataElementValue(2) = "ABA"      'Description
        Next

        'LX - ASSIGNED NUMBER
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\LX"))
        oSegment.DataElementValue(1) = "123456"      'Assigned Number

        'HS - HEALTH SCREENING
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\HS"))
        oSegment.DataElementValue(1) = "IDIDID"      'Health Screening Type Code
        oSegment.DataElementValue(2) = "CC"      'Date Time Period Format Qualifier
        oSegment.DataElementValue(3) = "A1B2C3D4E5"      'Date Time Period
        oSegment.DataElementValue(4) = "001"      'Status Reason Code

        'IMM - IMMUNIZATION STATUS CODE
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\IMM"))
        oSegment.DataElementValue(1) = "FLU"      'Immunization Type Code
        oSegment.DataElementValue(2) = "D8"      'Date Time Period Format Qualifier
        oSegment.DataElementValue(3) = "19871128"      'Date Time Period
        oSegment.DataElementValue(4) = "1"      'Immunization Status Code

        'IMM - IMMUNIZATION STATUS CODE
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\IMM(2)"))
        oSegment.DataElementValue(1) = "TETANU"      'Immunization Type Code
        oSegment.DataElementValue(2) = "D8"      'Date Time Period Format Qualifier
        oSegment.DataElementValue(3) = "19700219"      'Date Time Period
        oSegment.DataElementValue(4) = "1"      'Immunization Status Code

        'IMM - IMMUNIZATION STATUS CODE
        ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\IMM(3)"))
        oSegment.DataElementValue(1) = "MUMPS"      'Immunization Type Code
        oSegment.DataElementValue(2) = "D8"      'Date Time Period Format Qualifier
        oSegment.DataElementValue(3) = "19750504"      'Date Time Period
        oSegment.DataElementValue(4) = "1"      'Immunization Status Code

        Dim nSesLoop As Integer
        For nSesLoop = 1 To 2 ' number of sessions
            'SES - ACADEMIC SESSION HEADER
            ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\SES\SES"))
            oSegment.DataElementValue(1) = "20010407"      'Date Time Period
            oSegment.DataElementValue(4) = "4"      'Session Code
            oSegment.DataElementValue(5) = "SPRING QUARTER 2001"      'Name
            oSegment.DataElementValue(6) = "D8"      'Date Time Period Format Qualifier
            oSegment.DataElementValue(7) = "20010407"      'Date Time Period
            oSegment.DataElementValue(8) = "D8"      'Date Time Period Format Qualifier
            oSegment.DataElementValue(9) = "20010630"      'Date Time Period
            oSegment.DataElementValue(10) = "21"      'Level of Individual, Test, or Course Code
            oSegment.DataElementValue(14) = "B35"      'Status Reason Code

            Dim nCrsLoop As Integer
            For nCrsLoop = 1 To 3 'number of courses ina session
                'CRS - COURSE RECORD
                ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\SES\CRS\CRS"))
                oSegment.DataElementValue(1) = "R"      'Basis for Academic Credit Code
                oSegment.DataElementValue(2) = "U"      'Academic Credit Type Code
                oSegment.DataElementValue(5) = "GRD"      'Academic Grade Qualifier
                oSegment.DataElementValue(6) = "AB"      'Academic Grade
                oSegment.DataElementValue(8) = "U"      'Academic Grade or Course Level Code
                oSegment.DataElementValue(12) = "12"      'Quantity
                oSegment.DataElementValue(14) = "BEGIN MATH"      'Name
                oSegment.DataElementValue(15) = "MAT101"      'Reference Identification
                oSegment.DataElementValue(16) = "MATH"      'Name
            Next    'nCrsLoop
        Next    'nSesLoop

        'TRAILING SEGMENTS ARE AUTOMATICALLY CREATED WHEN FREDI COMMITS (SAVES)
        'THE EDI DOCUMENT OBJECT INTO AN EDI FILE.
        oEdiDoc.Save(sPath + sEdifile)

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

        MessageBox.Show("Done. Output = " + sPath + sEdifile)


    End Sub
    

    Click here to download a trial version of the Framework EDI