troubleshooting Question

Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser

Avatar of RGuillermo
RGuillermoFlag for United States of America asked on
Visual Basic.NET
9 Comments1 Solution1017 ViewsLast Modified:
Hello experts,
The following sub works justfine the first time its called by the main program.
The second time it stop without giving any message.
it stops when trying to execute :

MyReader.TextFieldType = FileIO.FieldType.Delimited

Is it not possible to open the same text file twice in the same program?
If each time I am opening and closing properly?

END USING is this sentence closing properly the file? or I need to do something else?
see sub below.
Regards

    Private Sub s_load_grades(ByVal p_per_num)
        Dim currentrow(150) As String, currentfield As String, r As Integer
        Dim a(25) As String, n As Integer, t1 As Integer, t2 As Integer
        t1 = a_per_nnn(p_per_num, 4)   ' lo que tiene que avanzar antes de hallar la data correcta.
        t2 = a_per_nnn(p_per_num, 3)      ' lo que tiene que leer una vez hallada la data correcta.

        Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(ss_tmp_fdr & "tmp_gra.txt")
            MyReader.TextFieldType = FileIO.FieldType.Delimited
            MyReader.SetDelimiters(",")
            r = 0
            While Not MyReader.EndOfData And r <= t1 And t1 > 0
                r += 1
                currentrow = MyReader.ReadFields()
            End While
            While Not MyReader.EndOfData And r >= t1 And r <= t1 + t2
                r += 1
                Try
                    currentrow = MyReader.ReadFields()
                    n = 0 'MsgBox(currentrow)
                    For Each currentfield In currentrow
                        n += 1
                        a_gra(r, n) = currentfield
                    Next
                Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                    MsgBox("Line " & ex.Message & "is not valid and will be skipped.")

                End Try
            End While

        End Using

    End Sub
ASKER CERTIFIED SOLUTION
Mike Tomlinson
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros