Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 Index Was Outside The Bounds of the Array Error

$
0
0
Hello, I am a bit of a newbie to programming but I know my way around pretty well. I have been getting an error when I debug my program and it says, "Index Was Outside The Bounds of the Array".

Here is my code:
Code:

        If lblFilePath1.Text IsNot "Label2" Then
            'Adds text to "FileName" file
            Dim fileContents As String = System.IO.File.ReadAllText("C:/Server/FilePath.txt")
            Dim lines() As String
            fileContents = fileContents.Replace(ControlChars.CrLf, ControlChars.Lf)
            lines = fileContents.Split(New Char() {ControlChars.Lf, ControlChars.Cr})
            lines(1) = lblFilePath1.Text
            System.IO.File.WriteAllText("C:/Server/FilePath.txt", String.Join(ControlChars.NewLine, lines))

It highlights lblFilePath1.Text when it gives me the error message. I'm not quite sure what to do, so I came here for help.

Thanks, robblie_bob

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>