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 214 file using 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 sLoopQlfr As String Dim sPath As String Dim sEdiFile As String Dim sSefFile As String btnTranslate.Enabled = False sPath = AppDomain.CurrentDomain.BaseDirectory sEdiFile = "214.X12" sSefFile = "214_004010.SEF" '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 TRANSLATE THE EDI FILE. ediSchemas.Set(oSchemas, oEdiDoc.GetSchemas) oSchemas.EnableStandardReference = False 'THIS OPTIONS STOPS FREDI FROM KEEPING ALL THE SEGMENTS IN MEMORY 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 ListBox1.Items.Add(oSegment.DataElement(9).Description & " = " & 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 = "B10" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'Reference Identification ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) 'Shipment Identification Number sValue = oSegment.DataElementValue(3) 'Standard Carrier Alpha Code End If 'Segment ID ElseIf sLoopID = "N1" Then 'If loop has more that one instance, then you should check for the qualifier that differentiates the loop instances here If sSegmentID = "N1" Then sLoopQlfr = oSegment.DataElementValue(1) 'In most cases the loop qualifier is the first element of the first segment in the loop, but not necessarily End If If sLoopQlfr = "SF" Then If sSegmentID = "N1" Then sValue = oSegment.DataElementValue(1) 'Entity Identifier Code ListBox1.Items.Add("Ship-From Name = " & oSegment.DataElementValue(2)) 'Name ElseIf sSegmentID = "N2" Then sValue = oSegment.DataElementValue(1) 'Name ElseIf sSegmentID = "N3" Then ListBox1.Items.Add("Ship-From Address = " & oSegment.DataElementValue(1)) 'Address Information ElseIf sSegmentID = "N4" Then ListBox1.Items.Add("Ship-From City = " & oSegment.DataElementValue(1)) 'City Name ListBox1.Items.Add("Ship-From State = " & oSegment.DataElementValue(2)) 'State or Province Code ListBox1.Items.Add("Ship-From Zip = " & oSegment.DataElementValue(3)) 'Postal Code End If 'Segment ID ElseIf sLoopQlfr = "ST" Then If sSegmentID = "N1" Then sValue = oSegment.DataElementValue(1) 'Entity Identifier Code ListBox1.Items.Add("Ship-To Name = " & oSegment.DataElementValue(2)) 'Name ElseIf sSegmentID = "N2" Then sValue = oSegment.DataElementValue(1) 'Name ElseIf sSegmentID = "N3" Then ListBox1.Items.Add("Ship-To Address = " & oSegment.DataElementValue(1)) 'Address Information ElseIf sSegmentID = "N4" Then ListBox1.Items.Add("Ship-To City = " & oSegment.DataElementValue(1)) 'City Name ListBox1.Items.Add("Ship-To State = " & oSegment.DataElementValue(2)) 'State or Province Code ListBox1.Items.Add("Ship-To Zip = " & oSegment.DataElementValue(3)) 'Postal Code End If 'Segment ID End If ElseIf sLoopID = "LX" Then If sSegmentID = "LX" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'Assigned Number ElseIf sSegmentID = "L11" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) End If 'Segment ID ElseIf sLoopID = "LX;AT7" Then If sSegmentID = "AT7" Then sValue = oSegment.DataElementValue(1) 'Shipment Status Code ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) 'Shipment Status or Appointment Reason Code sValue = oSegment.DataElementValue(3) 'Shipment Appointment Status Code sValue = oSegment.DataElementValue(4) 'Shipment Status or Appointment Reason Code sValue = oSegment.DataElementValue(5) 'Date sValue = oSegment.DataElementValue(6) 'Time sValue = oSegment.DataElementValue(7) 'Time Code ElseIf sSegmentID = "MS1" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'City Name ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) 'State or Province Code ElseIf sSegmentID = "MS2" Then sValue = oSegment.DataElementValue(1) 'Standard Carrier Alpha Code ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) 'Equipment Number sValue = oSegment.DataElementValue(3) 'Equipment Description Code End If 'Segment ID ElseIf sLoopID = "LX;SPO" Then If sSegmentID = "SPO" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'Purchase Order Number ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) 'Reference Identification sValue = oSegment.DataElementValue(3) 'Unit or Basis for Measurement Code ListBox1.Items.Add(oSegment.DataElement(4).Description & " = " & oSegment.DataElementValue(4)) 'Quantity sValue = oSegment.DataElementValue(5) 'Weight Unit Code sValue = oSegment.DataElementValue(6) 'Weight 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