Hi, im using visual studio 2010, and for my recent assignment i am having difficulty when closing a text file. My program is to read in the data from a text file and then do some calculations and then output the result.

My text file Measurements.txt looks like this:


Each set of 4 numbers represents miles, yards, feet, and inches. For example, 5 miles, 11 yards, 4 feet, and 3 inches are the first four, then the second four is the second set of data. My problem is that when i try to close the text file, it only reads the first set of data and computations, then an error occurs that stops it from running. I've tried using a for loop to try and loop the data just 2 times, but that doesnt seem to work. Any suggestions?

If Closing is the same as Line Reading then see if this helps.

Dim myCoolFile As String = "C:\test.txt" '// your file.
        Dim line1 As Integer = 0, line2 As Integer = 1, line3 As Integer = 2, line4 As Integer = 3
        If IO.File.Exists(myCoolFile) Then
            Dim myCoolFileLines() As String = IO.File.ReadAllLines(myCoolFile) '// load your file as a string array.
            Dim tempStr As String = ""
            For i As Integer = 0 To myCoolFileLines.Length - 1 Step +4
                tempStr = myCoolFileLines(line1)
                line1 += 3
                tempStr &= " - " & myCoolFileLines(line2)
                line2 += 3
                tempStr &= " - " & myCoolFileLines(line3)
                line3 += 3
                tempStr &= " - " & myCoolFileLines(line4)
                line4 += 3
        End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.