Import Data From a Text File
Public Class Form1
Dim Word(5) As String
Dim X, y As Integer
Dim inFile As IO.StreamReader
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
For y = 1 To 5
'y=1 at first: the first word that is added to the listbox is Word(1)
lstBox1.Items.Add(Word(y))
Next y
btnGo.Enabled = False
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' This program reads 5 data Items
'inFile opens the notpad file
inFile = IO.File.OpenText("C:\Users\administrator\VB\spelling.txt")
'this function loops around until there is no more data
Do Until inFile.Peek = -1
X = X + 1
'Word(1) stores the first word; Word(2) stores the second word and so forth
Word(X) = inFile.ReadLine
Loop
'you must close the file
inFile.Close()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class