Protected Sub btnStartValidation_Click(sender As Object, e As EventArgs) Handles btnStartValidation.Click

        Dim oEdidoc As ediDocument = Nothing
        Dim oSchemas As ediSchemas = Nothing
        Dim oSegment As ediDataSegment = Nothing
        Dim oWarnings As ediWarnings = Nothing
        Dim oWarning As ediWarning = Nothing

        Dim sPath As String

        sPath = AppDomain.CurrentDomain.BaseDirectory

        'instantiate edi document
        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

        'load SEF files only when needed
        oSchemas.Option(SchemasOptionIDConstants.OptSchemas_SetOnDemand) = 1

        'SEF files are actually not loaded at the LoadSchema command. The approriate SEF file
        'is loaded during the LoadEdiString command
        oEdidoc.LoadSchema(sPath & "files\270_X092A1_SemRef.SEF", SchemaTypeIDConstants.Schema_Standard_Exchange_Format)
        oEdidoc.LoadSchema(sPath & "files\271_X092A1_SemRef.SEF", SchemaTypeIDConstants.Schema_Standard_Exchange_Format)
        oEdidoc.LoadSchema(sPath & "files\276_X093A1_SemRef.SEF", SchemaTypeIDConstants.Schema_Standard_Exchange_Format)
        oEdidoc.LoadSchema(sPath & "files\277_X093A1_SemRef.SEF", SchemaTypeIDConstants.Schema_Standard_Exchange_Format)
        oEdidoc.LoadSchema(sPath & "files\820_X061A1_SemRef.SEF", SchemaTypeIDConstants.Schema_Standard_Exchange_Format)
        oEdidoc.LoadSchema(sPath & "files\834_X095A1_SemRef.SEF", SchemaTypeIDConstants.Schema_Standard_Exchange_Format)
        oEdidoc.LoadSchema(sPath & "files\835_X091A1_SemRef.SEF", SchemaTypeIDConstants.Schema_Standard_Exchange_Format)
        oEdidoc.LoadSchema(sPath & "files\837_X096A1_SemRef.SEF", SchemaTypeIDConstants.Schema_Standard_Exchange_Format)
        oEdidoc.LoadSchema(sPath & "files\837_X097A1_SemRef.SEF", SchemaTypeIDConstants.Schema_Standard_Exchange_Format)
        oEdidoc.LoadSchema(sPath & "files\837_X098A1_SemRef.SEF", SchemaTypeIDConstants.Schema_Standard_Exchange_Format)
        

        Dim sEdiString As String = Trim(txtEdiString.Text)

        'load edi string.  The appropriate SEF file is also loaded at this time.
        oEdidoc.LoadEdiString(sEdiString)

        'iterate through all segments in the EDI file so that they can get validated
        'get first data segment
        ediDataSegment.Set(oSegment, oEdidoc.FirstDataSegment)
        Do While Not oSegment Is Nothing
            'get next segment
            ediDataSegment.Set(oSegment, oSegment.Next)
        Loop

        'instantiate warnings collection object
        ediWarnings.Set(oWarnings, oEdidoc.GetWarnings)

        'get count of error found
        Dim nErrCount As Integer = oWarnings.Count
        lblMessage.Text = "There were " + Str(nErrCount) + " errors found in the EDI file."

        'display error messages
        lstErrorList.Items.Clear()

        Dim i As Integer
        For i = 1 To nErrCount
            'instantiate a warning object from the warnings collection
            ediWarning.Set(oWarning, oWarnings.Warning(i))

            lstErrorList.Items.Add(oWarning.LoopId + " " + oWarning.SegmentId + " " + oWarning.Description)
        Next
        
    End Sub