Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click 'This is just an example to show how to use the Framework EDI component in VB .NET to translate an 856 EDI file. Dim oEdiDoc As ediDocument Dim oSchema As ediSchema Dim oSchemas As ediSchemas Dim oSegment As ediDataSegment Dim sSegmentID As String Dim sLoopSection As String Dim nArea As Integer Dim sValue As String Dim sHLevel As String Dim sEntity As String Dim sPath As String Me.Cursor = Cursors.WaitCursor sPath = AppDomain.CurrentDomain.BaseDirectory & "\" 'CREATES EDIDOC 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 + "856_X12-4010.SEF", 0)) 'LOADS THE EDI FILE oEdiDoc.LoadEdi(sPath + "856.X12") '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 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 ListBox1.Items.Add(oSegment.DataElement(6).Description & " = " & oSegment.DataElementValue(6)) 'Interchange Sender ID sValue = oSegment.DataElementValue(7) 'Interchange ID Qualifier ListBox1.Items.Add(oSegment.DataElement(8).Description & " = " & 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 ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & 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 'sLoopSection ElseIf nArea = 1 Then If sLoopSection = "" Then If sSegmentID = "ST" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'Transaction Set Identifier Code ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) 'Transaction Set Control Number ElseIf sSegmentID = "BSN" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'Transaction Set Purpose Code ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) 'Shipment Identification ListBox1.Items.Add(oSegment.DataElement(3).Description & " = " & oSegment.DataElementValue(3)) 'Date ListBox1.Items.Add(oSegment.DataElement(4).Description & " = " & oSegment.DataElementValue(4)) 'Time ListBox1.Items.Add(oSegment.DataElement(5).Description & " = " & oSegment.DataElementValue(5)) 'Hierarchical Structure Code End If 'sSegmentID End If 'sLoopSection ElseIf nArea = 2 Then If sLoopSection = "HL" And sSegmentID = "HL" Then sHLevel = oSegment.DataElementValue(3) 'Get the Hierarchical level code End If If sHLevel = "S" Then 'Shipment If sLoopSection = "HL" Then If sSegmentID = "TD1" Then If oSegment.DataElementValue(1) = "TKT" Then ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) ListBox1.Items.Add(oSegment.DataElement(7).Description & " = " & oSegment.DataElementValue(7)) End If ElseIf sSegmentID = "TD5" Then ListBox1.Items.Add(oSegment.DataElement(3).Description & " = " & oSegment.DataElementValue(3)) ListBox1.Items.Add(oSegment.DataElement(5).Description & " = " & oSegment.DataElementValue(5)) ElseIf sSegmentID = "TD3" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) ListBox1.Items.Add(oSegment.DataElement(3).Description & " = " & oSegment.DataElementValue(3)) ElseIf sSegmentID = "DTM" Then If oSegment.DataElementValue(1) = "011" Then 'Shipped date ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) ElseIf oSegment.DataElementValue(1) = "017" Then 'Estimated delivery date ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) End If ElseIf sSegmentID = "REF" Then If oSegment.DataElementValue(1) = "BM" Then ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) End If End If ElseIf sLoopSection = "HL;N1" Then If sSegmentID = "N1" Then sEntity = oSegment.DataElementValue(1) 'Entity identifier End If If sEntity = "BT" Then 'Bill-To information If sSegmentID = "N1" Then ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) ListBox1.Items.Add(oSegment.DataElement(4).Description & " = " & oSegment.DataElementValue(4)) ElseIf sSegmentID = "N3" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) ElseIf sSegmentID = "N4" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) ListBox1.Items.Add(oSegment.DataElement(3).Description & " = " & oSegment.DataElementValue(3)) End If ElseIf sEntity = "ST" Then 'Ship-To information If sSegmentID = "N1" Then ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) ListBox1.Items.Add(oSegment.DataElement(4).Description & " = " & oSegment.DataElementValue(4)) ElseIf sSegmentID = "N3" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) ElseIf sSegmentID = "N4" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) ListBox1.Items.Add(oSegment.DataElement(3).Description & " = " & oSegment.DataElementValue(3)) End If End If End If 'sLoopsection ElseIf sHLevel = "O" Then 'Order If sLoopSection = "HL" Then If sSegmentID = "PRF" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) ListBox1.Items.Add(oSegment.DataElement(4).Description & " = " & oSegment.DataElementValue(4)) ElseIf sSegmentID = "REF" Then If oSegment.DataElementValue(1) = "IV" Then ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) End If End If End If ElseIf sHLevel = "I" Then 'Item If sLoopSection = "HL" Then If sSegmentID = "LIN" Then ListBox1.Items.Add(oSegment.DataElement(3).Description & " = " & oSegment.DataElementValue(3)) ElseIf sSegmentID = "SN1" Then ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) ListBox1.Items.Add(oSegment.DataElement(3).Description & " = " & oSegment.DataElementValue(3)) ListBox1.Items.Add(oSegment.DataElement(5).Description & " = " & oSegment.DataElementValue(5)) ListBox1.Items.Add(oSegment.DataElement(6).Description & " = " & oSegment.DataElementValue(6)) ListBox1.Items.Add(oSegment.DataElement(8).Description & " = " & oSegment.DataElementValue(8)) ElseIf sSegmentID = "PRF" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) ListBox1.Items.Add(oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2)) ListBox1.Items.Add(oSegment.DataElement(4).Description & " = " & oSegment.DataElementValue(4)) ElseIf sSegmentID = "PID" Then If oSegment.DataElementValue(1) = "F" Then ListBox1.Items.Add(oSegment.DataElement(5).Description & " = " & oSegment.DataElementValue(5)) End If End If End If End If ElseIf nArea = 3 Then If sLoopSection = "" Then If sSegmentID = "CTT" Then ListBox1.Items.Add(oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1)) 'Number of Line Items End If 'sSegmentID End If 'sLoopSection End If 'nArea 'GETS THE NEXT DATA SEGMENT ediDataSegment.Set(oSegment, oSegment.Next) Loop Me.Cursor = Cursors.Default 'DESTROY OBJECTS oSchema.Dispose() oSchemas.Dispose() oEdiDoc.Dispose() MessageBox.Show("Done") End Sub