Private Sub
cmdTranslate810_Click()
Dim oEdiDoc As
Fredi.ediDocument
Dim oSegment As
Fredi.ediDataSegment
Dim nArea As Integer
Dim sLoopSection As String
Dim sSegmentID As String
Dim sSefFile As String
Dim sEdiFile As String
sSefFile = "810_X12-4010.SEF"
sEdiFile = "810.x12"
Set oEdiDoc = New
Fredi.ediDocument
'LOAD SEF FILE
oEdiDoc.LoadSchema sSefFile, Schema_Standard_Exchange_Format
'LOAD EDI FILE
oEdiDoc.LoadEdi sEdiFile
'GET FIRST SEGMENT
Set oSegment = oEdiDoc.FirstDataSegment
'ITERATE THRU EACH SEGMENT
While Not oSegment Is
Nothing
nArea = oSegment.Area
sLoopSection = oSegment.LoopSection
sSegmentID = oSegment.ID
'segments are uniquely identified by
their segment ID,
'and loopsection, and area they are in.
If nArea = 0 Then
If sSegmentID =
"ISA" Then
txtReceiverID.txt =
oSegment.DataElementValue(8)
End If
ElseIf nArea = 1 Then
If sLoopSection =
"" Then
If
sSegmentID = "ST" Then
txtTransactionSetControlNo.txt = oSegment.DataElementValue(2)
ElseIf
sSegmentID = "BIG" Then
txtShippedDate.Text = oSegment.DataElementValue(1)
txtInvoiceNo.Text = oSegment.DataElementValue(2)
txtPONumber.Text = oSegment.DataElementValue(4)
End If
ElseIf
sLoopSection = "N1" Then
If
sSegmentID = "N1" Then
sEntity =
oSegment.DataElementValue(1)
End If
If
sEntity = "ST" Then 'SHIP
TO
If
sSegmentID = "N1" Then
txtShipToName.Text = oSegment.DataElementValue(2)
txtShipToDUNS.Text = oSegment.DataElementValue(4)
ElseIf
sSegmentID = "N3" Then
txtShipToAddress.Text = oSegment.DataElementValue(1)
ElseIf
sSegmentID = "N4" Then
txtShipToCity.Text = oSegment.DataElementValue(1)
txtShipToState.Text = oSegment.DataElementValue(2)
txtShipToZip.Text = oSegment.DataElementValue(3)
End
If
ElseIf
sEntity = "BT" Then 'BILL
TO
If
sSegmentID = "N1" Then
txtBillToName.Text = oSegment.DataElementValue(2)
txtBillToDUNS.Text = oSegment.DataElementValue(4)
ElseIf
sSegmentID = "N3" Then
txtBillToAddress.Text = oSegment.DataElementValue(1)
ElseIf
sSegmentID = "N4" Then
txtBillToCity.Text = oSegment.DataElementValue(1)
txtBillToState.Text = oSegment.DataElementValue(2)
txtBillToZip.Text = oSegment.DataElementValue(3)
End
If
End If
End If
End If
'GET NEXT SEGMENT
Set oSegment = oSegment.Next
Wend
End Sub
The sample program above is to demonstrate how one can
easily use the Framework EDI component to read an EDI
file. The component manages the arduous detail of the EDI
file structure so that programmers translating EDI files can just simply "map"
the properties of the
component into output variables in their program.
Inbound mapping is the process of
specifying a specific data element of an EDI file to a variable of an existing system
(e.g. a database field). The advantages of having the mapping done at
the source code level (as compared to at an application level) are
flexibility, robustness and accuracy.
Click
here to download more sample programs
Click
here to download Framework EDI