Private Sub btnTranslate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTranslate.Click 'This is just an example program to demonstrate how to translate an EDI X12 204 file 'using the Framework EDI component in VB.NET Dim oEdiDoc As ediDocument Dim oSchema As ediSchema Dim oSchemas As ediSchemas Dim oSegment As ediDataSegment Dim sSegmentID As String Dim sLoopID As String Dim nArea As Integer Dim sValue As String Dim sEdiFile As String Dim sSefFile As String Dim sPath As String Dim sQlfr As String Dim sEntityIdfr As String btnTranslate.Enabled = False sPath = AppDomain.CurrentDomain.BaseDirectory sSefFile = "204_4010.SEF" sEdiFile = "204.X12" 'CREATES EDI DOCUMENT OBJECT ediDocument.Set(oEdiDoc, New ediDocument) 'USE ONLY THE SEF FILE PROVIDED, AND NOT USE THE BUILT-IN STANDARD REFERENCE TABLE FOR TRANSLATING THE EDI FILE. THIS IMPROVES PERFORMANCE. ediSchemas.Set(oSchemas, oEdiDoc.GetSchemas) oSchemas.EnableStandardReference = False 'THIS OPTIONS STOPS FREDI FROM KEEPING ALL THE SEGMENTS IN MEMORY. THIS IMPROVES PERFORMANCE. oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardOnly 'LOADS THE SEF FILE ediSchema.Set(oSchema, oEdiDoc.ImportSchema(sPath & sSefFile, 0)) 'LOADS THE EDI FILE oEdiDoc.LoadEdi(sPath & sEdiFile) 'GETS THE FIRST DATA SEGMENT ediDataSegment.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 sLoopID = oSegment.LoopSection nArea = oSegment.Area If nArea = 0 Then If sLoopID = "" 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 ListBox1.Items.Add(oSegment.DataElement(5).Description & " = " & oSegment.DataElementValue(5)) 'Interchange ID Qualifier ListBox1.Items.Add(oSegment.DataElement(6).Description & " = " & 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 ListBox1.Items.Add(oSegment.DataElement(13).Description & " = " & 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 ListBox1.Items.Add(oSegment.DataElement(6).Description & " = " & 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 'sLoopID ElseIf nArea = 1 Then If sLoopID = "" Then If sSegmentID = "ST" Then sValue = oSegment.DataElementValue(1) 'Transaction Set Identifier Code ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) 'Transaction Set Control Number ElseIf sSegmentID = "B2" Then sValue = oSegment.DataElementValue(1) 'Tariff Service Code sValue = oSegment.DataElementValue(2) 'Standard Carrier Alpha Code sValue = oSegment.DataElementValue(3) 'Standard Point Location Code ListBox1.Items.Add(oSegment.DataElement(4).Description & " = " & oSegment.DataElementValue(4)) 'Shipment Identification Number sValue = oSegment.DataElementValue(5) 'Weight Unit Code sValue = oSegment.DataElementValue(6) 'Shipment Method of Payment sValue = oSegment.DataElementValue(7) 'Shipment Qualifier ElseIf sSegmentID = "B2A" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'Transaction Set Purpose Code sValue = oSegment.DataElementValue(2) 'Application Type ElseIf sSegmentID = "L11" Then sQlfr = oSegment.DataElementValue(2) 'Reference Identification Qualifier If sQlfr = "CO" Then ListBox1.Items.Add("Customer Order Number = " & oSegment.DataElementValue(1)) 'Reference Identification") ElseIf sQlfr = "14" Then ListBox1.Items.Add("Master Account Number = " & oSegment.DataElementValue(1)) 'Reference Identification End If ElseIf sSegmentID = "G62" Then sValue = oSegment.DataElementValue(1) 'Date Qualifier sValue = oSegment.DataElementValue(2) 'Date End If 'Segment ID ElseIf sLoopID = "N7" Then If sSegmentID = "N7" Then sValue = oSegment.DataElementValue(1) 'Equipment Initial ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) 'Equipment Number End If 'sSegmentID End If 'sLoopID ElseIf nArea = 2 Then If sLoopID = "S5" Then If sSegmentID = "S5" Then sEntityIdfr = oSegment.DataElementValue(2) End If End If If sEntityIdfr = "LD" Then 'LOAD If sLoopID = "S5" Then If sSegmentID = "S5" Then sValue = oSegment.DataElementValue(1) 'Stop Sequence Number sValue = oSegment.DataElementValue(2) 'Stop Reason Code ListBox1.Items.Add("Load " + oSegment.DataElement(3).Description & " = " & oSegment.DataElementValue(3)) 'Weight sValue = oSegment.DataElementValue(4) 'Weight Unit Code sValue = oSegment.DataElementValue(5) 'Number of Units Shipped sValue = oSegment.DataElementValue(6) 'Unit or Basis for Measurement Code ElseIf sSegmentID = "L11" Then sQlfr = oSegment.DataElementValue(2) 'Reference Identification Qualifier If sQlfr = "RU" Then ListBox1.Items.Add("Load Route Number = " & oSegment.DataElementValue(1)) 'Reference Identification") End If ElseIf sSegmentID = "G62" Then sQlfr = oSegment.DataElementValue(1) 'Date Qualifier If sQlfr = "78" Then ListBox1.Items.Add("Load Delivery Appointment Scheduled Date = " & oSegment.DataElementValue(2)) 'Date End If End If 'Segment ID ElseIf sLoopID = "S5;N1" Then If sSegmentID = "N1" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'Entity Identifier Code ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) 'Name sValue = oSegment.DataElementValue(3) 'Identification Code Qualifier sValue = oSegment.DataElementValue(4) 'Identification Code ElseIf sSegmentID = "N3" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'Address Information sValue = oSegment.DataElementValue(2) 'Address Information ElseIf sSegmentID = "N4" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'City Name sValue = oSegment.DataElementValue(2) 'State or Province Code sValue = oSegment.DataElementValue(3) 'Postal Code ElseIf sSegmentID = "G61" Then sValue = oSegment.DataElementValue(1) 'Contact Function Code ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'Name End If 'Segment ID ElseIf sLoopID = "S5;OID" Then If sSegmentID = "OID" Then sValue = oSegment.DataElementValue(1) 'Reference Identification ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) 'Purchase Order Number sValue = oSegment.DataElementValue(3) 'Reference Identification sValue = oSegment.DataElementValue(4) 'Unit or Basis for Measurement Code sValue = oSegment.DataElementValue(5) 'Quantity sValue = oSegment.DataElementValue(6) 'Weight Unit Code ListBox1.Items.Add(oSegment.DataElement(7).Description & " = " & oSegment.DataElementValue(7)) 'Weight ElseIf sSegmentID = "LAD" Then sValue = oSegment.DataElementValue(1) 'Packaging Form Code sValue = oSegment.DataElementValue(2) 'Lading Quantity sValue = oSegment.DataElementValue(3) 'Weight Unit Code sValue = oSegment.DataElementValue(4) 'Unit Weight sValue = oSegment.DataElementValue(5) 'Weight Unit Code sValue = oSegment.DataElementValue(6) 'Weight sValue = oSegment.DataElementValue(7) 'Product/Service ID Qualifier ListBox1.Items.Add(oSegment.DataElement(8).Description & " = " & oSegment.DataElementValue(8)) 'Product/Service ID sValue = oSegment.DataElementValue(9) 'Product/Service ID Qualifier sValue = oSegment.DataElementValue(10) 'Product/Service ID sValue = oSegment.DataElementValue(11) 'Product/Service ID Qualifier sValue = oSegment.DataElementValue(12) 'Product/Service ID ListBox1.Items.Add(oSegment.DataElement(13).Description & " = " & oSegment.DataElementValue(13)) 'Lading Description End If 'sSegmentID End If 'sLoopID ElseIf sEntityIdfr = "UL" Then 'UNLOAD If sLoopID = "S5" Then If sSegmentID = "S5" Then sValue = oSegment.DataElementValue(1) 'Stop Sequence Number sValue = oSegment.DataElementValue(2) 'Stop Reason Code ListBox1.Items.Add("Unload " + oSegment.DataElement(3).Description & " = " & oSegment.DataElementValue(3)) 'Weight sValue = oSegment.DataElementValue(4) 'Weight Unit Code sValue = oSegment.DataElementValue(5) 'Number of Units Shipped sValue = oSegment.DataElementValue(6) 'Unit or Basis for Measurement Code ElseIf sSegmentID = "L11" Then sQlfr = oSegment.DataElementValue(2) 'Reference Identification Qualifier If sQlfr = "RU" Then ListBox1.Items.Add("Unload Route Number = " & oSegment.DataElementValue(1)) 'Reference Identification") End If ElseIf sSegmentID = "G62" Then sQlfr = oSegment.DataElementValue(1) 'Date Qualifier If sQlfr = "78" Then ListBox1.Items.Add("Unload Delivery Appointment Scheduled Date = " & oSegment.DataElementValue(2)) 'Date End If End If 'Segment ID ElseIf sLoopID = "S5;N1" Then If sSegmentID = "N1" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'Entity Identifier Code ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) 'Name sValue = oSegment.DataElementValue(3) 'Identification Code Qualifier sValue = oSegment.DataElementValue(4) 'Identification Code ElseIf sSegmentID = "N3" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'Address Information sValue = oSegment.DataElementValue(2) 'Address Information ElseIf sSegmentID = "N4" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'City Name sValue = oSegment.DataElementValue(2) 'State or Province Code sValue = oSegment.DataElementValue(3) 'Postal Code ElseIf sSegmentID = "G61" Then sValue = oSegment.DataElementValue(1) 'Contact Function Code ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'Name End If 'Segment ID ElseIf sLoopID = "S5;OID" Then If sSegmentID = "OID" Then sValue = oSegment.DataElementValue(1) 'Reference Identification ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) 'Purchase Order Number sValue = oSegment.DataElementValue(3) 'Reference Identification sValue = oSegment.DataElementValue(4) 'Unit or Basis for Measurement Code sValue = oSegment.DataElementValue(5) 'Quantity sValue = oSegment.DataElementValue(6) 'Weight Unit Code ListBox1.Items.Add(oSegment.DataElement(7).Description & " = " & oSegment.DataElementValue(7)) 'Weight ElseIf sSegmentID = "LAD" Then sValue = oSegment.DataElementValue(1) 'Packaging Form Code sValue = oSegment.DataElementValue(2) 'Lading Quantity sValue = oSegment.DataElementValue(3) 'Weight Unit Code sValue = oSegment.DataElementValue(4) 'Unit Weight sValue = oSegment.DataElementValue(5) 'Weight Unit Code sValue = oSegment.DataElementValue(6) 'Weight sValue = oSegment.DataElementValue(7) 'Product/Service ID Qualifier ListBox1.Items.Add(oSegment.DataElement(8).Description & " = " & oSegment.DataElementValue(8)) 'Product/Service ID sValue = oSegment.DataElementValue(9) 'Product/Service ID Qualifier sValue = oSegment.DataElementValue(10) 'Product/Service ID sValue = oSegment.DataElementValue(11) 'Product/Service ID Qualifier sValue = oSegment.DataElementValue(12) 'Product/Service ID ListBox1.Items.Add(oSegment.DataElement(13).Description & " = " & oSegment.DataElementValue(13)) 'Lading Description End If 'sSegmentID End If 'sLoopID End If 'sEntityIdfr ElseIf nArea = 3 Then If sLoopID = "" Then If sSegmentID = "L3" Then sValue = oSegment.DataElementValue(1) 'Weight sValue = oSegment.DataElementValue(2) 'Weight Qualifier sValue = oSegment.DataElementValue(3) 'Freight Rate sValue = oSegment.DataElementValue(4) 'Rate/Value Qualifier sValue = oSegment.DataElementValue(5) 'Charge sValue = oSegment.DataElementValue(6) 'Advances sValue = oSegment.DataElementValue(7) 'Prepaid Amount sValue = oSegment.DataElementValue(8) 'Special Charge or Allowance Code sValue = oSegment.DataElementValue(9) 'Volume sValue = oSegment.DataElementValue(10) 'Volume Unit Qualifier sValue = oSegment.DataElementValue(11) 'Lading Quantity End If 'sSegmentID End If 'sLoopID End If 'nArea 'GETS THE NEXT DATA SEGMENT ediDataSegment.Set(oSegment, oSegment.Next) Loop 'DESTROY OBJECTS oSchema.Dispose() oSchemas.Dispose() oEdiDoc.Dispose() MessageBox.Show("Done.") End Sub