DavidIQ
01-07-2005, 02:56 PM
I'm about to give up on this thing now. I've been working on it for hours and I keep getting the same error. The way I have it written I'm thinking it should work but it's not. :confused:
Here's what I'm trying to do:
There is a text file that is written by the same program that I've made. Each line of the text file has a name on it. I'd like to assign the names of this text file to an array so that I can generate a random list from the names on that text file (or from the array). I haven't gotten as far as debugging the randomizing part of the code because for some reason the array doesn't seem to want to take in the values from the sreStreamReader.ReadLine() code.
Since I have the exception catcher I'm getting an error message: "Object reference not set to an instance of an object." There is another part of the code that has a similar look and I'm getting the same error but since it's not doing a catch I'm getting an error from the IDE which causes the program to freeze. The first error is referencing what's in bold here as being the problem:
'Reads in sequential access file
Try
sreStreamReader = IO.File.OpenText("list.txt")
'Assigns each value in the file to each position in the array
Do Until sreStreamReader.Peek() = -1
List(intCount) = sreStreamReader.ReadLine()
intCount = intCount + 1
Loop
Catch ex As Exception
MessageBox.Show(ex.Message, "List", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
End Try
Here are my variables declared for this segment:
Dim intCount As Integer
Dim strAssign As String
'Array for the list
Dim List() As String
The second error is coming from more or less the same code elsewhere. Am I missing something here? I'll appreciate it if someone can decipher this beast :huh: . Thanks. :-\
Here's what I'm trying to do:
There is a text file that is written by the same program that I've made. Each line of the text file has a name on it. I'd like to assign the names of this text file to an array so that I can generate a random list from the names on that text file (or from the array). I haven't gotten as far as debugging the randomizing part of the code because for some reason the array doesn't seem to want to take in the values from the sreStreamReader.ReadLine() code.
Since I have the exception catcher I'm getting an error message: "Object reference not set to an instance of an object." There is another part of the code that has a similar look and I'm getting the same error but since it's not doing a catch I'm getting an error from the IDE which causes the program to freeze. The first error is referencing what's in bold here as being the problem:
'Reads in sequential access file
Try
sreStreamReader = IO.File.OpenText("list.txt")
'Assigns each value in the file to each position in the array
Do Until sreStreamReader.Peek() = -1
List(intCount) = sreStreamReader.ReadLine()
intCount = intCount + 1
Loop
Catch ex As Exception
MessageBox.Show(ex.Message, "List", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
End Try
Here are my variables declared for this segment:
Dim intCount As Integer
Dim strAssign As String
'Array for the list
Dim List() As String
The second error is coming from more or less the same code elsewhere. Am I missing something here? I'll appreciate it if someone can decipher this beast :huh: . Thanks. :-\