[RESOLVED] Add Text to Array
Hello, I am having an issue with my coding. I believe that this is correct, but when I try to load the form it results in an error. I am trying to load each individual line of the Cat1.txt file into the wordsarray that I have declared publicly because I will use the array in other subs. When I try this, I get a runtime error that states "NullReferenceException was unhandled." Is there a better way to code this? Also, how could I exclude the first line of the text file from the array?
Code:
Public Class MainForm
Dim wordsarray() As String
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim inFile As IO.StreamReader
Dim strInfo As String
Dim intSubscript As Integer = 0
If IO.File.Exists("Cat1.txt") Then
inFile = IO.File.OpenText("Cat1.txt")
Do Until inFile.Peek = -1
strInfo = inFile.ReadLine
wordsarray(intSubscript) = strInfo
intSubscript = intSubscript + 1
Loop
inFile.Close()
Else
MessageBox.Show("Can't find the Cat1.txt file", "Category 1 File Missing", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
End Class
Any help would be appreciated.
Re: [RESOLVED] Add Text to Array
Thank you so much, that worked perfectly!