I have a procedure that saves the name of all of the labels that are clicked to a text file, I then need to load these names later on so that I can change the colour of them to red. This is the procedure that should load the names of the labels from the file:
Sub LoadSeats()
If My.Computer.FileSystem.FileExists("Seats.txt") = True Then 'Checks if the seats.txt file is present
FileReader = New StreamReader("Seats.txt")
NumOfBookedSeats = FileReader.ReadLine() 'Finds out how many seats have been booked
For intCounter = 1 To NumOfBookedSeats
SeatList.Add(FileReader.ReadLine)
BookedSeat.Name = SeatList(intCounter)
BookedSeat.BackColor = Color.Red
BookedSeat.ForeColor = Color.Red
Next
Else
FileWriter = New StreamWriter("Seats.txt")
FileWriter.WriteLine(0)
FileWriter.Close()
End If
End Sub
An error occurs on the this line:
BookedSeat.Name = SeatList(intCounter)
The error says "NullReferenceException was unhandled. Object reference not set to an instance of an object." Im not sure why this is occuring, any help is appreciated. The 'Seats.txt' file contains this:
4 'This is the number of names in the file
lblG1 'This line and every one following it will contain the name of a label
lblH1
lblI1
lblJ1