'This is just an example program to show how to translate an EDI X12 130 Student Educational Record
    'in VB6 with the Framework EDI component

    Option Explicit

    Private Sub Command1_Click()
        Dim oEdiDoc As Fredi.ediDocument
        Dim oSchema As Fredi.ediSchema
        Dim oSchemas As Fredi.ediSchemas
        Dim oSegment As Fredi.ediDataSegment
        Dim sSegmentID As String
        Dim sLoopSection As String
        Dim nArea As Integer
        Dim sN1LoopQlfr As String
        Dim sQlfr As String
        Dim sValue As String
        Dim sPath As String
        Dim nCourseCount As Integer
        Dim sSession As String
     
        sPath = App.Path & "\"
    
        'CREATES EDIDOC OBJECT
        Set oEdiDoc = New Fredi.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 TRANSLATE THE EDI FILE.
        Set oSchemas = oEdiDoc.GetSchemas
        oSchemas.EnableStandardReference = False
     
        'THIS OPTIONS STOPS FREDI FROM KEEPING ALL THE SEGMENTS IN MEMORY
        oEdiDoc.CursorType = Cursor_ForwardOnly
     
        'LOADS THE SEF FILE
        Set oSchema = oEdiDoc.LoadSchema(sPath & "130_4010.SEF", 0)
     
        'LOADS THE EDI FILE
        oEdiDoc.LoadEdi sPath & "130.x12"
     
        'GETS THE FIRST DATA SEGMENT
        Set oSegment = oEdiDoc.FirstDataSegment
     
        'LOOP THAT WILL TRAVERSE THRU EDI FILE FROM TOP TO BOTTOM
        Do While Not oSegment Is Nothing
     
            'DATA SEGMENTS WILL BE IDENTIFIED BY THEIR ID, THE LOOP SECTION AND AREA
            '(OR TABLE) NUMBER THAT THEY ARE IN.
            sSegmentID = oSegment.ID
            sLoopSection = oSegment.LoopSection
            nArea = oSegment.Area
     
            If nArea = 0 Then
                If sLoopSection = "" Then
                   If sSegmentID = "ISA" Then
                       sValue = oSegment.DataElementValue(1)     'Authorization Information Qualifier
                       sValue = oSegment.DataElementValue(2)     'Authorization Information
                       sValue = oSegment.DataElementValue(3)     'Security Information Qualifier
                       sValue = oSegment.DataElementValue(4)     'Security Information
                       sValue = oSegment.DataElementValue(5)     'Interchange ID Qualifier
                       sValue = oSegment.DataElementValue(6)     'Interchange Sender ID
                       sValue = oSegment.DataElementValue(7)     'Interchange ID Qualifier
                       sValue = oSegment.DataElementValue(8)     'Interchange Receiver ID
                       sValue = oSegment.DataElementValue(9)     'Interchange Date
                       sValue = oSegment.DataElementValue(10)     'Interchange Time
                       sValue = oSegment.DataElementValue(11)     'Interchange Control Standards Identifier
                       sValue = oSegment.DataElementValue(12)     'Interchange Control Version Number
                       sValue = oSegment.DataElementValue(13)     'Interchange Control Number
                       sValue = oSegment.DataElementValue(14)     'Acknowledgment Requested
                       sValue = oSegment.DataElementValue(15)     'Usage Indicator
                       sValue = oSegment.DataElementValue(16)     'Component Element Separator
     
                   ElseIf sSegmentID = "GS" Then
                       sValue = oSegment.DataElementValue(1)     'Functional Identifier Code
                       sValue = oSegment.DataElementValue(2)     'Application Sender's Code
                       sValue = oSegment.DataElementValue(3)     'Application Receiver's Code
                       sValue = oSegment.DataElementValue(4)     'Date
                       sValue = oSegment.DataElementValue(5)     'Time
                       sValue = oSegment.DataElementValue(6)     'Group Control Number
                       sValue = oSegment.DataElementValue(7)     'Responsible Agency Code
                       sValue = oSegment.DataElementValue(8)     'Version / Release / Industry Identifier Code
                   End If   'sSegmentID
                End If   'sLoopSection
     
            ElseIf nArea = 1 Then
                If sLoopSection = "" Then
                   If sSegmentID = "ST" Then
                       sValue = oSegment.DataElementValue(1)     'Transaction Set Identifier Code
                       sValue = oSegment.DataElementValue(2)     'Transaction Set Control Number
                       nCourseCount = -1
     
                   ElseIf sSegmentID = "BGN" Then
                       sValue = oSegment.DataElementValue(1)     'Transaction Set Purpose Code
                       sValue = oSegment.DataElementValue(2)     'Reference Identification
                       sValue = oSegment.DataElementValue(3)     'Date
                       sValue = oSegment.DataElementValue(4)     'Time
                       sValue = oSegment.DataElementValue(5)     'Time Code
     
                   ElseIf sSegmentID = "ERP" Then
                       sValue = oSegment.DataElementValue(1)     'Transaction Type Code
                       sValue = oSegment.DataElementValue(2)     'Status Reason Code
     
                   ElseIf sSegmentID = "REF" Then
                       sValue = oSegment.DataElementValue(1)     'Reference Identification Qualifier
                       sValue = oSegment.DataElementValue(2)     'Reference Identification
     
                   ElseIf sSegmentID = "DMG" Then
                       sValue = oSegment.DataElementValue(1)     'Date Time Period Format Qualifier
                       sValue = oSegment.DataElementValue(2)     'Date Time Period
                       sValue = oSegment.DataElementValue(3)     'Gender Code
                       sValue = oSegment.DataElementValue(4)     'Marital Status Code
                       sValue = oSegment.DataElementValue(5)     'Race or Ethnicity Code
                       sValue = oSegment.DataElementValue(6)     'Citizenship Status Code
     
                   ElseIf sSegmentID = "PCL" Then
                       sValue = oSegment.DataElementValue(1)     'Identification Code Qualifier
                       sValue = oSegment.DataElementValue(2)     'Identification Code
                       sValue = oSegment.DataElementValue(3)     'Date Time Period Format Qualifier
                       sValue = oSegment.DataElementValue(4)     'Date Time Period
                       sValue = oSegment.DataElementValue(5)     'Academic Degree Code
                       sValue = oSegment.DataElementValue(6)     'Date Time Period
                       sValue = oSegment.DataElementValue(7)     'Description
                   End If   'Segment ID
     
                ElseIf sLoopSection = "N1" Then
                    If sSegmentID = "N1" Then
                       sN1LoopQlfr = oSegment.DataElementValue(1)
                    End If
                    If sN1LoopQlfr = "AS" Then            'Post Secondary Education Sender
                        If sSegmentID = "N1" Then
                            txtPostSecondaryEducationSender.Text = oSegment.DataElementValue(2)      'Name
                            txtUniversityCode.Text = oSegment.DataElementValue(4)      'Identification Code
                    
                        ElseIf sSegmentID = "N3" Then
                            txtEducationSenderAddress.Text = oSegment.DataElementValue(1)     'Address Information
                    
                        ElseIf sSegmentID = "N4" Then
                            txtEducationSenderCity.Text = oSegment.DataElementValue(1)     'City Name
                            txtEducationSenderState.Text = oSegment.DataElementValue(2)     'State or Province Code
                            txtEducationSenderZip.Text = oSegment.DataElementValue(3)     'Postal Code
                        End If   'Segment ID
                
                    ElseIf sN1LoopQlfr = "AT" Then  'Post Secondary Education Receiver
                        If sSegmentID = "N1" Then
                            sValue = oSegment.DataElementValue(2)      'Name
                            sValue = oSegment.DataElementValue(4)      'Identification Code
                    
                        ElseIf sSegmentID = "N3" Then
                            sValue = oSegment.DataElementValue(1)     'Address Information
                    
                        ElseIf sSegmentID = "N4" Then
                            sValue = oSegment.DataElementValue(1)     'City Name
                            sValue = oSegment.DataElementValue(2)     'State or Province Code
                            sValue = oSegment.DataElementValue(3)     'Postal Code
                        End If   'Segment ID
                    
                    End If 'sN1LoopQlfr
     
                ElseIf sLoopSection = "IN1" Then
                   If sSegmentID = "IN1" Then
                       sValue = oSegment.DataElementValue(1)     'Entity Type Qualifier
                       sValue = oSegment.DataElementValue(2)     'Name Type Code
                       sValue = oSegment.DataElementValue(3)     'Entity Identifier Code
                       sValue = oSegment.DataElementValue(4)     'Reference Identification Qualifier
                       sValue = oSegment.DataElementValue(5)     'Reference Identification
                       sValue = oSegment.DataElementValue(6)     'Individual Relationship Code
                       sValue = oSegment.DataElementValue(7)     'Level of Individual, Test, or Course Code
     
                   ElseIf sSegmentID = "IN2" Then
                        sQlfr = oSegment.DataElementValue(1)
                        If sQlfr = "05" Then
                            txtIndividualLastname.Text = oSegment.DataElementValue(2)      'Name
                        ElseIf sQlfr = "02" Then
                            txtIndividualFirstname.Text = oSegment.DataElementValue(2)      'Name
                        ElseIf sQlfr = "15" Then
                            txtIndividualMaidenname.Text = oSegment.DataElementValue(2)      'Name
                        End If
                   End If   'Segment ID
     
                ElseIf sLoopSection = "SST" Then
                   If sSegmentID = "SST" Then
                       sValue = oSegment.DataElementValue(1)     'Status Reason Code
     
                   ElseIf sSegmentID = "N1" Then
                       sQlfr = oSegment.DataElementValue(1)     'Entity Identifier Code
                       If sQlfr = "HS" Then
                            txtHighSchool.Text = oSegment.DataElementValue(2)      'Name
                            txtHighScoolCode.Text = oSegment.DataElementValue(4)      'Identification Code
                        End If
                   End If   'Segment ID
     
                ElseIf sLoopSection = "TST" Then
                   If sSegmentID = "TST" Then
                       sValue = oSegment.DataElementValue(1)     'Educational Test or Requirement Code
                       sValue = oSegment.DataElementValue(2)     'Name
                       sValue = oSegment.DataElementValue(3)     'Date Time Period Format Qualifier
                       sValue = oSegment.DataElementValue(4)     'Date Time Period
                       sValue = oSegment.DataElementValue(5)     'Reference Identification
                       sValue = oSegment.DataElementValue(6)     'Reference Identification
                       sValue = oSegment.DataElementValue(7)     'Level of Individual, Test, or Course Code
                       sValue = oSegment.DataElementValue(8)     'Level of Individual, Test, or Course Code
                       sValue = oSegment.DataElementValue(9)     'Date Time Period
                       sValue = oSegment.DataElementValue(10)     'Test Norm Type Code
                       sValue = oSegment.DataElementValue(11)     'Test Norming Period Code
                       sValue = oSegment.DataElementValue(12)     'Language Code
                       sValue = oSegment.DataElementValue(13)     'Date Time Period
                       sValue = oSegment.DataElementValue(14)     'Yes/No Condition or Response Code
                       sValue = oSegment.DataElementValue(15)     'Yes/No Condition or Response Code
                   End If   'sSegmentID
                End If   'sLoopSection
     
            ElseIf nArea = 2 Then
                If sLoopSection = "LX" Then
                   If sSegmentID = "LX" Then
                       sValue = oSegment.DataElementValue(1)     'Assigned Number
     
                   ElseIf sSegmentID = "HS" Then
                       sValue = oSegment.DataElementValue(1)     'Health Screening Type Code
                       sValue = oSegment.DataElementValue(2)     'Date Time Period Format Qualifier
                       sValue = oSegment.DataElementValue(3)     'Date Time Period
                       sValue = oSegment.DataElementValue(4)     'Status Reason Code
     
                   ElseIf sSegmentID = "IMM" Then
                       sValue = oSegment.DataElementValue(1)     'Immunization Type Code
                       sValue = oSegment.DataElementValue(2)     'Date Time Period Format Qualifier
                       sValue = oSegment.DataElementValue(3)     'Date Time Period
                       sValue = oSegment.DataElementValue(4)     'Immunization Status Code
                       sValue = oSegment.DataElementValue(5)     'Report Type Code
                   End If   'Segment ID
     
                ElseIf sLoopSection = "LX;HC" Then
                   If sSegmentID = "HC" Then
                       sValue = oSegment.DataElementValue(1)     'Disease Condition Type Code
                       sValue = oSegment.DataElementValue(2)     'Medical Treatment Type Code
                       sValue = oSegment.DataElementValue(3)     'Date Time Period Format Qualifier
                       sValue = oSegment.DataElementValue(4)     'Date Time Period
                       sValue = oSegment.DataElementValue(5)     'Yes/No Condition or Response Code
     
                   ElseIf sSegmentID = "N1" Then
                       sValue = oSegment.DataElementValue(1)     'Entity Identifier Code
                       sValue = oSegment.DataElementValue(2)     'Name
                       sValue = oSegment.DataElementValue(3)     'Identification Code Qualifier
                       sValue = oSegment.DataElementValue(4)     'Identification Code
                       sValue = oSegment.DataElementValue(5)     'Entity Relationship Code
                       sValue = oSegment.DataElementValue(6)     'Entity Identifier Code
     
                   ElseIf sSegmentID = "N2" Then
                       sValue = oSegment.DataElementValue(1)     'Name
                       sValue = oSegment.DataElementValue(2)     'Name
     
                   ElseIf sSegmentID = "PER" Then
                       sValue = oSegment.DataElementValue(1)     'Contact Function Code
                       sValue = oSegment.DataElementValue(2)     'Name
                       sValue = oSegment.DataElementValue(3)     'Communication Number Qualifier
                       sValue = oSegment.DataElementValue(4)     'Communication Number
                       sValue = oSegment.DataElementValue(5)     'Communication Number Qualifier
                       sValue = oSegment.DataElementValue(6)     'Communication Number
                       sValue = oSegment.DataElementValue(7)     'Communication Number Qualifier
                       sValue = oSegment.DataElementValue(8)     'Communication Number
                       sValue = oSegment.DataElementValue(9)     'Contact Inquiry Reference
     
                   ElseIf sSegmentID = "N3" Then
                       sValue = oSegment.DataElementValue(1)     'Address Information
                       sValue = oSegment.DataElementValue(2)     'Address Information
     
                   ElseIf sSegmentID = "N4" Then
                       sValue = oSegment.DataElementValue(1)     'City Name
                       sValue = oSegment.DataElementValue(2)     'State or Province Code
                       sValue = oSegment.DataElementValue(3)     'Postal Code
                       sValue = oSegment.DataElementValue(4)     'Country Code
                       sValue = oSegment.DataElementValue(5)     'Location Qualifier
                       sValue = oSegment.DataElementValue(6)     'Location Identifier
                   End If   'Segment ID
     
                ElseIf sLoopSection = "LX;SES" Then
                   If sSegmentID = "SES" Then
                       sValue = oSegment.DataElementValue(1)     'Date Time Period
                       sValue = oSegment.DataElementValue(2)     'Count
                       sValue = oSegment.DataElementValue(3)     'Date Time Period
                       sValue = oSegment.DataElementValue(4)     'Session Code
                       sSession = oSegment.DataElementValue(5)      'Name
                       sValue = oSegment.DataElementValue(6)     'Date Time Period Format Qualifier
                       sValue = oSegment.DataElementValue(7)     'Date Time Period
                       sValue = oSegment.DataElementValue(8)     'Date Time Period Format Qualifier
                       sValue = oSegment.DataElementValue(9)     'Date Time Period
                       sValue = oSegment.DataElementValue(10)     'Level of Individual, Test, or Course Code
                       sValue = oSegment.DataElementValue(11)     'Identification Code Qualifier
                       sValue = oSegment.DataElementValue(12)     'Identification Code
                       sValue = oSegment.DataElementValue(13)     'Name
                       sValue = oSegment.DataElementValue(14)     'Status Reason Code
     
                   ElseIf sSegmentID = "SSE" Then
                       sValue = oSegment.DataElementValue(1)     'Date
     
                   ElseIf sSegmentID = "NTE" Then
                       sValue = oSegment.DataElementValue(1)     'Note Reference Code
                       sValue = oSegment.DataElementValue(2)     'Description
     
                   ElseIf sSegmentID = "N1" Then
                       sValue = oSegment.DataElementValue(1)     'Entity Identifier Code
                       sValue = oSegment.DataElementValue(2)     'Name
                       sValue = oSegment.DataElementValue(3)     'Identification Code Qualifier
                       sValue = oSegment.DataElementValue(4)     'Identification Code
     
                   ElseIf sSegmentID = "N3" Then
                       sValue = oSegment.DataElementValue(1)     'Address Information
     
                   ElseIf sSegmentID = "N4" Then
                       sValue = oSegment.DataElementValue(1)     'City Name
                       sValue = oSegment.DataElementValue(2)     'State or Province Code
                       sValue = oSegment.DataElementValue(3)     'Postal Code
                   End If   'Segment ID
     
                ElseIf sLoopSection = "LX;SES;SUM" Then
                   If sSegmentID = "SUM" Then
                       sValue = oSegment.DataElementValue(1)     'Academic Credit Type Code
                       sValue = oSegment.DataElementValue(2)     'Academic Grade or Course Level Code
                       sValue = oSegment.DataElementValue(3)     'Yes/No Condition or Response Code
                       sValue = oSegment.DataElementValue(4)     'Quantity
                       sValue = oSegment.DataElementValue(5)     'Quantity
                       sValue = oSegment.DataElementValue(6)     'Quantity
                       sValue = oSegment.DataElementValue(7)     'Range Minimum
                       sValue = oSegment.DataElementValue(8)     'Range Maximum
                       sValue = oSegment.DataElementValue(9)     'Academic Grade Point Average
                       sValue = oSegment.DataElementValue(10)     'Yes/No Condition or Response Code
                       sValue = oSegment.DataElementValue(11)     'Class Rank
                       sValue = oSegment.DataElementValue(12)     'Quantity
                   End If   'Segment ID
     
                ElseIf sLoopSection = "LX;SES;CRS" Then
                   If sSegmentID = "CRS" Then
                        nCourseCount = nCourseCount + 1
    '                   sValue = oSegment.DataElementValue(1)     'Basis for Academic Credit Code
    '                   sValue = oSegment.DataElementValue(2)     'Academic Credit Type Code
    '                   sValue = oSegment.DataElementValue(3)     'Quantity
    '                   sValue = oSegment.DataElementValue(4)     'Quantity
    '                   sValue = oSegment.DataElementValue(5)     'Academic Grade Qualifier
    '                   sValue = oSegment.DataElementValue(6)     'Academic Grade
    '                   sValue = oSegment.DataElementValue(7)     'Yes/No Condition or Response Code
    '                   sValue = oSegment.DataElementValue(8)     'Academic Grade or Course Level Code
    '                   sValue = oSegment.DataElementValue(9)     'Course Repeat or No Count Indicator Code
    '                   sValue = oSegment.DataElementValue(10)     'Identification Code Qualifier
    '                   sValue = oSegment.DataElementValue(11)     'Identification Code
    '                   sValue = oSegment.DataElementValue(12)     'Quantity
    '                   sValue = oSegment.DataElementValue(13)     'Level of Individual, Test, or Course Code
    '                   sValue = oSegment.DataElementValue(14)     'Name
                       txtCourse(nCourseCount).Text = oSegment.DataElementValue(15)      'Reference Identification
    '                   sValue = oSegment.DataElementValue(16)     'Name
     
                   ElseIf sSegmentID = "NTE" Then
                       'sValue = oSegment.DataElementValue(1)     'Note Reference Code
                       sValue = oSegment.DataElementValue(2)     'Description
                        If Left(sValue, 5) = "INSTR" Then
                            txtSessionName(nCourseCount) = sSession
                            txtInstructor(nCourseCount) = sValue
                        End If
                   
                   End If   'Segment ID
     
                ElseIf sLoopSection = "LX;SES;CRS;MKS" Then
                   If sSegmentID = "MKS" Then
                       sValue = oSegment.DataElementValue(1)     'Mark Code Type
                       sValue = oSegment.DataElementValue(2)     'Academic Grade Qualifier
                       sValue = oSegment.DataElementValue(3)     'Academic Grade
                   End If   'Segment ID
     
                ElseIf sLoopSection = "LX;SES;DEG" Then
                   If sSegmentID = "DEG" Then
                       sValue = oSegment.DataElementValue(1)     'Academic Degree Code
                       sValue = oSegment.DataElementValue(2)     'Date Time Period Format Qualifier
                       sValue = oSegment.DataElementValue(3)     'Date Time Period
                       sValue = oSegment.DataElementValue(4)     'Description
     
                   ElseIf sSegmentID = "FOS" Then
                       sValue = oSegment.DataElementValue(1)     'Academic Field of Study Level or Type Code
                       sValue = oSegment.DataElementValue(2)     'Identification Code Qualifier
                       sValue = oSegment.DataElementValue(3)     'Identification Code
                       sValue = oSegment.DataElementValue(4)     'Description
     
                   ElseIf sSegmentID = "NTE" Then
                       sValue = oSegment.DataElementValue(1)     'Note Reference Code
                       sValue = oSegment.DataElementValue(2)     'Description
                   End If  'sSegmentID
                End If  'sLoopSection
            End If  'nArea
     
            'GETS THE NEXT DATA SEGMENT
            Set oSegment = oSegment.Next
     
        Loop
     
        'DESTROY OBJECTS
        Set oEdiDoc = Nothing
        Set oSchema = Nothing
        Set oSchemas = Nothing
        Set oSegment = Nothing

        MsgBox "Done"
    
    End Sub
    

    Click here to download a trial version of the Framework EDI