instantwin
New member
- Joined
- Nov 2, 2009
- Messages
- 4
- Programming Experience
- Beginner
is there a way to make an array but instead of listing the things yourself, you open a text file with a bunch of words and use those?
Private Function LoadArray() As Integer
Dim fileReader As System.IO.StreamReader
Dim fileString As String
Dim iCount As Integer = 0
fileReader = _
My.Computer.FileSystem.OpenTextFileReader("C:\TextFile.txt")
While Not fileReader.EndOfStream
fileString = fileReader.ReadLine()
MyList.Add(fileString)
ReDim Preserve MyArray(iCount)
MyArray(iCount) = fileString
iCount += 1
End While
Return iCount ' Return the number of elements in the array
End Function
Dim words As String() = IO.File.ReadAllLines("file path here")
Assuming that the file contains only the words and one per line:VB.NET:Dim words As String() = IO.File.ReadAllLines("file path here")