Results 1 to 11 of 11

Thread: [RESOLVED]IOException was unhandled

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    9

    [RESOLVED]IOException was unhandled

    Basically I'm trying to save the source of a site and then read certain lines, this works once. The second time I get this error: "IOException was unhandled"
    Code:
        Public Function GetNumberOfLines(ByVal File_Path As String) As Integer
            Dim SR As New StreamReader(File_Path)
            Dim NumberOfLines As Integer
            Do While SR.Peek >= 0
                SR.ReadLine()
                NumberOfLines += 1
            Loop
            Return NumberOfLines
            SR.Close()
        End Function
    
        Public Function ReadALine(ByVal File_Path As String, ByVal TotalLines As Integer, ByVal Line2Read As Integer) As String
            Dim Buffer As Array
            Dim Line As String
            If TotalLines < Line2Read Or Line2Read = 0 Then
                Return "No such line exists"
            Else
                Line2Read -= 1
                Buffer = File.ReadAllLines(File_Path)
                Line = Buffer(Line2Read)
                Return Line
            End If
        End Function
    
        Private Function StealCar()
            CarTheft = ReadALine(log, GetNumberOfLines(log), 58)
            CarTheft1 = Microsoft.VisualBasic.Left(ReadALine(log, GetNumberOfLines(log), 58), 6)
            CarTheftC = ReadALine(log, GetNumberOfLines(log), 68)
            CarTheftC1 = Microsoft.VisualBasic.Left(ReadALine(log, GetNumberOfLines(log), 68), 6)
    
            If CarTheft1 = "oTimer" Then
                If Len(CarTheft) = "20" Then
                    CarTimer1 = Microsoft.VisualBasic.Left((Microsoft.VisualBasic.Right(ReadALine(log, GetNumberOfLines(log), 58), 5)), 3)
                ElseIf Len(CarTheft) = "19" Then
                    CarTimer1 = Microsoft.VisualBasic.Left((Microsoft.VisualBasic.Right(ReadALine(log, GetNumberOfLines(log), 58), 4)), 2)
                ElseIf Len(CarTheft) = "18" Then
                    CarTimer1 = Microsoft.VisualBasic.Left((Microsoft.VisualBasic.Right(ReadALine(log, GetNumberOfLines(log), 58), 3)), 1)
                End If
            ElseIf CarTheftC1 = "oTimer" Then
                If Len(CarTheftC) = "20" Then
                    CarTimer1 = Microsoft.VisualBasic.Left((Microsoft.VisualBasic.Right(ReadALine(log, GetNumberOfLines(log), 68), 5)), 3)
                ElseIf Len(CarTheftC) = "19" Then
                    CarTimer1 = Microsoft.VisualBasic.Left((Microsoft.VisualBasic.Right(ReadALine(log, GetNumberOfLines(log), 68), 4)), 2)
                ElseIf Len(CarTheftC) = "18" Then
                    CarTimer1 = Microsoft.VisualBasic.Left((Microsoft.VisualBasic.Right(ReadALine(log, GetNumberOfLines(log), 68), 3)), 1)
                End If
            Else
                CarTimer1 = "0"
    
    
            End If
    
        End Function
    
        Private Function DoCrimes()
            DoCrime = ReadALine(log, GetNumberOfLines(log), 55)
            DoCrime1 = Microsoft.VisualBasic.Left(ReadALine(log, GetNumberOfLines(log), 55), 6)
            If DoCrime1 = "oTimer" Then
                If Len(DoCrime) = "20" Then
                    CrimeTimer1 = Microsoft.VisualBasic.Left((Microsoft.VisualBasic.Right(ReadALine(log, GetNumberOfLines(log), 55), 5)), 3)
                ElseIf Len(DoCrime) = "19" Then
                    CrimeTimer1 = Microsoft.VisualBasic.Left((Microsoft.VisualBasic.Right(ReadALine(log, GetNumberOfLines(log), 55), 4)), 2)
                ElseIf Len(DoCrime) = "18" Then
                    CrimeTimer1 = Microsoft.VisualBasic.Left((Microsoft.VisualBasic.Right(ReadALine(log, GetNumberOfLines(log), 55), 3)), 1)
                End If
            Else
                CrimeTimer1 = "0"
    
            End If
        End Function
    
        Private Sub GetSource()
            Dim savef As New System.IO.StreamWriter(log)
            savef.Write(source)
            savef.Close()
            DoCrimes()
            StealCar()
        End Sub
    I've searched and I found quite a few of these threads, it's about not closing something correctly but I just can't figure out what I'm doing wrong
    I call GetSource() to make this work

    I've been having trouble with this for a while now, so yea any help is much appreciated
    Last edited by Xeno154; Jul 19th, 2009 at 03:26 PM. Reason: highlighted the problem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width