Protected Sub btnTranslate_Click(sender As Object, e As EventArgs) Handles btnTranslate.Click

        Dim oEdiDoc As ediDocument = Nothing
        Dim oSchemas As ediSchemas = Nothing
        Dim oSegment As ediDataSegment = Nothing

        Dim sSegmentID As String
        Dim sLoopSection As String
        Dim nArea As String

        Dim sValue As String
        Dim sEdiString As String

        Dim sQlfr As String = ""
        Dim sPath As String = AppDomain.CurrentDomain.BaseDirectory

        'Instantiate oEdi Document object
        ediDocument.Set(oEdiDoc, New ediDocument)

        'set cursor type to forward only to be memory efficient
        oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardOnly

        'disable internal standard reference library
        ediSchemas.Set(oSchemas, oEdiDoc.GetSchemas)
        oSchemas.EnableStandardReference = False
        'oSchemas.Option(SchemasOptionIDConstants.OptSchemas_VersionRestrict) = 1

        oSchemas.Option(SchemasOptionIDConstants.OptSchemas_SetOnDemand) = 1

        'Load Sef file
        oEdiDoc.LoadSchema(sPath & "files\810_004010.EVAL0.SEF", SchemaTypeIDConstants.Schema_Standard_Exchange_Format)

        'Get EDI string from form field
        sEdiString = Trim(txtEdiString.Text)

        'Load EDI string
        oEdiDoc.LoadEdiString(sEdiString)

        'Get first segment of EDI file
        ediDataSegment.Set(oSegment, oEdiDoc.FirstDataSegment())
        'Iterate through each segment of the EDI file
        Do While Not oSegment Is Nothing
            'Get ID, Loopsection and Area of segment to identify data segment
            sSegmentID = oSegment.ID
            sLoopSection = oSegment.LoopSection
            nArea = oSegment.Area

            If nArea = 0 Then
                If sLoopSection = "" Then
                    If sSegmentID = "ISA" Then  'map the its data elements
                        sValue = oSegment.DataElementValue(1)       ' Authorization Information Qualifier (I01) 
                        sValue = oSegment.DataElementValue(2)       ' Authorization Information (I02) 
                        sValue = oSegment.DataElementValue(3)       ' Security Information Qualifier (I03) 
                        sValue = oSegment.DataElementValue(4)       ' Security Information (I04) 
                        sValue = oSegment.DataElementValue(5)       ' Interchange ID Qualifier (I05) 
                        sValue = oSegment.DataElementValue(6)       ' Interchange Sender ID (I06) 
                        sValue = oSegment.DataElementValue(7)       ' Interchange ID Qualifier (I05) 
                        sValue = oSegment.DataElementValue(8)       ' Interchange Receiver ID (I07) 
                        sValue = oSegment.DataElementValue(9)       ' Interchange Date (I08) 
                        sValue = oSegment.DataElementValue(10)      ' Interchange Time (I09) 
                        sValue = oSegment.DataElementValue(11)      ' Interchange Control Standards Identifier (I10) 
                        sValue = oSegment.DataElementValue(12)      ' Interchange Control Version Number (I11) 
                        sValue = oSegment.DataElementValue(13)      ' Interchange Control Number (I12) 
                        ListBox1.Items.Add("Interchange Control Number: " + sValue)
                        sValue = oSegment.DataElementValue(14)      ' Acknowledgment Requested (I13) 
                        sValue = oSegment.DataElementValue(15)      ' Usage Indicator (I14) 
                        sValue = oSegment.DataElementValue(16)      ' Component Element Separator (I15) 

                    ElseIf sSegmentID = "GS" Then
                        sValue = oSegment.DataElementValue(1)       ' Functional Identifier Code (479) 
                        sValue = oSegment.DataElementValue(2)       ' Application Sender's Code (142) 
                        sValue = oSegment.DataElementValue(3)       ' Application Receiver's Code (124) 
                        sValue = oSegment.DataElementValue(4)       ' Date (373) 
                        sValue = oSegment.DataElementValue(5)       ' Time (337) 
                        sValue = oSegment.DataElementValue(6)       ' Group Control Number (28) 
                        ListBox1.Items.Add("Group Control Number: " + sValue)
                        sValue = oSegment.DataElementValue(7)       ' Responsible Agency Code (455) 
                        sValue = oSegment.DataElementValue(8)       ' Version / Release / Industry Identifier Code (480) 

                    End If
                End If

            ElseIf nArea = 1 Then
                If sLoopSection = "" Then
                    If sSegmentID = "ST" Then
                        sValue = oSegment.DataElementValue(1)       ' Transaction Set Identifier Code (143) 
                        sValue = oSegment.DataElementValue(2)       ' Transaction Set Control Number (329) 
                        ListBox1.Items.Add("Transaction Set Control Number: " + sValue)

                    ElseIf sSegmentID = "BIG" Then
                        sValue = oSegment.DataElementValue(1)       ' Date (373) 
                        ListBox1.Items.Add("Invoice Date: " + sValue)
                        sValue = oSegment.DataElementValue(2)       ' Invoice Number (76) 
                        ListBox1.Items.Add("Invoice Number: " + sValue)
                        sValue = oSegment.DataElementValue(3)       ' Date (373) 
                        sValue = oSegment.DataElementValue(4)       ' Purchase Order Number (324) 
                        sValue = oSegment.DataElementValue(5)       ' Release Number (328) 
                        sValue = oSegment.DataElementValue(6)       ' Change Order Sequence Number (327) 
                        sValue = oSegment.DataElementValue(7)       ' Transaction Type Code (640) 
                        sValue = oSegment.DataElementValue(8)       ' Transaction Set Purpose Code (353) 
                        sValue = oSegment.DataElementValue(9)       ' Action Code (306) 
                        sValue = oSegment.DataElementValue(10)      ' Invoice Number (76) 

                    ElseIf sSegmentID = "ITD" Then
                        sValue = oSegment.DataElementValue(1)       ' Terms Type Code (336) 
                        sValue = oSegment.DataElementValue(2)       ' Terms Basis Date Code (333) 
                        ListBox1.Items.Add("Terms Basis Date Code: " + sValue)
                        sValue = oSegment.DataElementValue(3)       ' Terms Discount Percent (338) 
                        sValue = oSegment.DataElementValue(4)       ' Terms Discount Due Date (370) 
                        sValue = oSegment.DataElementValue(5)       ' Terms Discount Days Due (351) 
                        sValue = oSegment.DataElementValue(6)       ' Terms Net Due Date (446) 
                        sValue = oSegment.DataElementValue(7)       ' Terms Net Days (386) 
                        sValue = oSegment.DataElementValue(8)       ' Terms Discount Amount (362) 
                        sValue = oSegment.DataElementValue(9)       ' Terms Deferred Due Date (388) 
                        sValue = oSegment.DataElementValue(10)      ' Deferred Amount Due (389) 
                        sValue = oSegment.DataElementValue(11)      ' Percent of Invoice Payable (342) 
                        sValue = oSegment.DataElementValue(12)      ' Description (352) 
                        sValue = oSegment.DataElementValue(13)      ' Day of Month (765) 
                        sValue = oSegment.DataElementValue(14)      ' Payment Method Code (107) 
                        sValue = oSegment.DataElementValue(15)      ' Percent (954) 

                    ElseIf sSegmentID = "FOB" Then
                        sValue = oSegment.DataElementValue(1)       ' Shipment Method of Payment (146) 
                        ListBox1.Items.Add("Shipment Method of Payment: " + sValue)
                        sValue = oSegment.DataElementValue(2)       ' Location Qualifier (309) 
                        sValue = oSegment.DataElementValue(3)       ' Description (352) 
                        sValue = oSegment.DataElementValue(4)       ' Transportation Terms Qualifier Code (334) 
                        sValue = oSegment.DataElementValue(5)       ' Transportation Terms Code (335) 
                        sValue = oSegment.DataElementValue(6)       ' Location Qualifier (309) 
                        sValue = oSegment.DataElementValue(7)       ' Description (352) 
                        sValue = oSegment.DataElementValue(8)       ' Risk of Loss Code (54) 
                        sValue = oSegment.DataElementValue(9)       ' Description (352) 

                    End If

                ElseIf sLoopSection = "N1" Then
                    'Get Qualifier
                    If sSegmentID = "N1" Then
                        sQlfr = oSegment.DataElementValue(1)    ' Entity Identifier Code (98) 
                    End If

                    If sQlfr = "ST" Then    'Ship To information
                        If sSegmentID = "N1" Then
                            sValue = oSegment.DataElementValue(1)       ' Entity Identifier Code (98) 
                            sValue = oSegment.DataElementValue(2)       ' Name (93) 
                            ListBox1.Items.Add("Ship To Name: " + sValue)
                            sValue = oSegment.DataElementValue(3)       ' Identification Code Qualifier (66) 
                            sValue = oSegment.DataElementValue(4)       ' Identification Code (67) 
                            sValue = oSegment.DataElementValue(5)       ' Entity Relationship Code (706) 
                            sValue = oSegment.DataElementValue(6)       ' Entity Identifier Code (98) 


                        ElseIf sSegmentID = "N3" Then
                            sValue = oSegment.DataElementValue(1)       ' Address Information (166) 
                            ListBox1.Items.Add("Ship To Address: " + sValue)
                            sValue = oSegment.DataElementValue(2)       ' Address Information (166) 

                        ElseIf sSegmentID = "N4" Then
                            sValue = oSegment.DataElementValue(1)       ' City Name (19) 
                            ListBox1.Items.Add("Ship To City: " + sValue)
                            sValue = oSegment.DataElementValue(2)       ' State or Province Code (156) 
                            sValue = oSegment.DataElementValue(3)       ' Postal Code (116) 
                            sValue = oSegment.DataElementValue(4)       ' Country Code (26) 
                            sValue = oSegment.DataElementValue(5)       ' Location Qualifier (309) 
                            sValue = oSegment.DataElementValue(6)       ' Location Identifier (310)

                        End If

                    ElseIf sQlfr = "BT" Then    'Bill To information
                        If sSegmentID = "N1" Then
                            sValue = oSegment.DataElementValue(1)       ' Entity Identifier Code (98) 
                            sValue = oSegment.DataElementValue(2)       ' Name (93) 
                            ListBox1.Items.Add("Bill To Name: " + sValue)
                            sValue = oSegment.DataElementValue(3)       ' Identification Code Qualifier (66) 
                            sValue = oSegment.DataElementValue(4)       ' Identification Code (67) 
                            sValue = oSegment.DataElementValue(5)       ' Entity Relationship Code (706) 
                            sValue = oSegment.DataElementValue(6)       ' Entity Identifier Code (98) 


                        ElseIf sSegmentID = "N3" Then
                            sValue = oSegment.DataElementValue(1)       ' Address Information (166) 
                            ListBox1.Items.Add("Bill To Address: " + sValue)
                            sValue = oSegment.DataElementValue(2)       ' Address Information (166) 

                        ElseIf sSegmentID = "N4" Then
                            sValue = oSegment.DataElementValue(1)       ' City Name (19) 
                            ListBox1.Items.Add("Bill To City: " + sValue)
                            sValue = oSegment.DataElementValue(2)       ' State or Province Code (156) 
                            sValue = oSegment.DataElementValue(3)       ' Postal Code (116) 
                            sValue = oSegment.DataElementValue(4)       ' Country Code (26) 
                            sValue = oSegment.DataElementValue(5)       ' Location Qualifier (309) 
                            sValue = oSegment.DataElementValue(6)       ' Location Identifier (310)

                        End If

                    ElseIf sQlfr = "RE" Then    'Remit To information
                        If sSegmentID = "N1" Then
                            sValue = oSegment.DataElementValue(1)       ' Entity Identifier Code (98) 
                            sValue = oSegment.DataElementValue(2)       ' Name (93) 
                            ListBox1.Items.Add("Remit To Name: " + sValue)
                            sValue = oSegment.DataElementValue(3)       ' Identification Code Qualifier (66) 
                            sValue = oSegment.DataElementValue(4)       ' Identification Code (67) 
                            sValue = oSegment.DataElementValue(5)       ' Entity Relationship Code (706) 
                            sValue = oSegment.DataElementValue(6)       ' Entity Identifier Code (98) 


                        ElseIf sSegmentID = "N3" Then
                            sValue = oSegment.DataElementValue(1)       ' Address Information (166) 
                            ListBox1.Items.Add("Remit To Address: " + sValue)
                            sValue = oSegment.DataElementValue(2)       ' Address Information (166) 

                        ElseIf sSegmentID = "N4" Then
                            sValue = oSegment.DataElementValue(1)       ' City Name (19) 
                            ListBox1.Items.Add("Remit To City: " + sValue)
                            sValue = oSegment.DataElementValue(2)       ' State or Province Code (156) 
                            sValue = oSegment.DataElementValue(3)       ' Postal Code (116) 
                            sValue = oSegment.DataElementValue(4)       ' Country Code (26) 
                            sValue = oSegment.DataElementValue(5)       ' Location Qualifier (309) 
                            sValue = oSegment.DataElementValue(6)       ' Location Identifier (310)

                        End If
                    End If
                End If

            ElseIf nArea = 2 Then
                If sLoopSection = "IT1" Then
                    If sSegmentID = "IT1" Then
                        sValue = oSegment.DataElementValue(1)       ' Assigned Identification (350) 
                        sValue = oSegment.DataElementValue(2)       ' Quantity Invoiced (358) 
                        ListBox1.Items.Add("Quantity Invoiced: " + sValue)
                        sValue = oSegment.DataElementValue(3)       ' Unit or Basis for Measurement Code (355) 
                        ListBox1.Items.Add("Unit: " + sValue)
                        sValue = oSegment.DataElementValue(4)       ' Unit Price (212) 
                        sValue = oSegment.DataElementValue(5)       ' Basis of Unit Price Code (639) 
                        sValue = oSegment.DataElementValue(6)       ' Product/Service ID Qualifier (235) 
                        sValue = oSegment.DataElementValue(7)       ' Product/Service ID (234) 
                        ListBox1.Items.Add("Product/Service ID: " + sValue)
                        sValue = oSegment.DataElementValue(8)       ' Product/Service ID Qualifier (235) 
                        sValue = oSegment.DataElementValue(9)       ' Product/Service ID (234) 
                        sValue = oSegment.DataElementValue(10)      ' Product/Service ID Qualifier (235) 
                        sValue = oSegment.DataElementValue(11)      ' Product/Service ID (234) 
                        sValue = oSegment.DataElementValue(12)      ' Product/Service ID Qualifier (235) 
                        sValue = oSegment.DataElementValue(13)      ' Product/Service ID (234) 
                        sValue = oSegment.DataElementValue(14)      ' Product/Service ID Qualifier (235) 
                        sValue = oSegment.DataElementValue(15)      ' Product/Service ID (234) 
                        sValue = oSegment.DataElementValue(16)      ' Product/Service ID Qualifier (235) 
                        sValue = oSegment.DataElementValue(17)      ' Product/Service ID (234) 
                        sValue = oSegment.DataElementValue(18)      ' Product/Service ID Qualifier (235) 
                        sValue = oSegment.DataElementValue(19)      ' Product/Service ID (234) 
                        sValue = oSegment.DataElementValue(20)      ' Product/Service ID Qualifier (235) 
                        sValue = oSegment.DataElementValue(21)      ' Product/Service ID (234) 
                        sValue = oSegment.DataElementValue(22)      ' Product/Service ID Qualifier (235) 
                        sValue = oSegment.DataElementValue(23)      ' Product/Service ID (234) 
                        sValue = oSegment.DataElementValue(24)      ' Product/Service ID Qualifier (235) 
                        sValue = oSegment.DataElementValue(25)      ' Product/Service ID (234) 

                    End If

                ElseIf sLoopSection = "IT1;PID" Then
                    If sSegmentID = "PID" Then
                        sValue = oSegment.DataElementValue(1)       ' Item Description Type (349) 
                        sValue = oSegment.DataElementValue(2)       ' Product/Process Characteristic Code (750) 
                        sValue = oSegment.DataElementValue(3)       ' Agency Qualifier Code (559) 
                        sValue = oSegment.DataElementValue(4)       ' Product Description Code (751) 
                        sValue = oSegment.DataElementValue(5)       ' Description (352) 
                        ListBox1.Items.Add("Description: " + sValue)
                        sValue = oSegment.DataElementValue(6)       ' Surface/Layer/Position Code (752) 
                        sValue = oSegment.DataElementValue(7)       ' Source Subqualifier (822) 
                        sValue = oSegment.DataElementValue(8)       ' Yes/No Condition or Response Code (1073) 
                        sValue = oSegment.DataElementValue(9)       ' Language Code (819) 

                    End If

                End If

            ElseIf nArea = 3 Then
                If sLoopSection = "" Then
                    If sSegmentID = "TDS" Then
                        sValue = oSegment.DataElementValue(1)       ' Amount (610) 
                        sValue = oSegment.DataElementValue(2)       ' Amount (610) 
                        sValue = oSegment.DataElementValue(3)       ' Amount (610) 
                        sValue = oSegment.DataElementValue(4)       ' Amount (610) 

                    ElseIf sSegmentID = "CAD" Then
                        sValue = oSegment.DataElementValue(1)       ' Transportation Method/Type Code (91) 
                        sValue = oSegment.DataElementValue(2)       ' Equipment Initial (206) 
                        sValue = oSegment.DataElementValue(3)       ' Equipment Number (207) 
                        sValue = oSegment.DataElementValue(4)       ' Standard Carrier Alpha Code (140) 
                        sValue = oSegment.DataElementValue(5)       ' Routing (387) 
                        sValue = oSegment.DataElementValue(6)       ' Shipment/Order Status Code (368) 
                        sValue = oSegment.DataElementValue(7)       ' Reference Identification Qualifier (128) 
                        sValue = oSegment.DataElementValue(8)       ' Reference Identification (127) 
                        sValue = oSegment.DataElementValue(9)       ' Service Level Code (284) 

                    ElseIf sSegmentID = "CTT" Then
                        sValue = oSegment.DataElementValue(1)       ' Number of Line Items (354) 
                        sValue = oSegment.DataElementValue(2)       ' Hash Total (347) 
                        sValue = oSegment.DataElementValue(3)       ' Weight (81) 
                        sValue = oSegment.DataElementValue(4)       ' Unit or Basis for Measurement Code (355) 
                        sValue = oSegment.DataElementValue(5)       ' Volume (183) 
                        sValue = oSegment.DataElementValue(6)       ' Unit or Basis for Measurement Code (355) 
                        sValue = oSegment.DataElementValue(7)       ' Description (352) 

                    ElseIf sSegmentID = "SE" Then
                        sValue = oSegment.DataElementValue(1)       ' Number of Included Segments (96) 
                        sValue = oSegment.DataElementValue(2)       ' Transaction Set Control Number (329) 

                    End If

                ElseIf sLoopSection = "ISS" Then
                    If sSegmentID = "ISS" Then
                        sValue = oSegment.DataElementValue(1)       ' Number of Units Shipped (382) 
                        sValue = oSegment.DataElementValue(2)       ' Unit or Basis for Measurement Code (355) 
                        sValue = oSegment.DataElementValue(3)       ' Weight (81) 
                        sValue = oSegment.DataElementValue(4)       ' Unit or Basis for Measurement Code (355) 
                        sValue = oSegment.DataElementValue(5)       ' Volume (183) 
                        sValue = oSegment.DataElementValue(6)       ' Unit or Basis for Measurement Code (355) 
                        sValue = oSegment.DataElementValue(7)       ' Quantity (380) 
                        sValue = oSegment.DataElementValue(8)       ' Weight (81) 

                    End If
                End If
            End If

            'Get next segment
            ediDataSegment.Set(oSegment, oSegment.Next)

        Loop


    End Sub