-
hey, i need a way to open a text file line by line
HEY THERE
WHATS UP
NO WAY
really?
and it reads the FIRST LINE, and puts it into text1.text
then it goes to the next, and puts its in text1.TAG
ect..
so i can put the first line in a place, second in a place, third, fourth, ECT..
so like:
HEY THERE-> text1.text
WHATS UP->text1.tag
NO WAY->text2.tag
really?->command.caption
like as an example
Well, anyone know?
-
Use Line Input
Code:
Dim iCount As Integer
Open "MyFile.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, Tmp
'Increment the line count
iCount = iCount + 1
'If it's Line2 then set Command1's caption
If iCount = 2 Then Command1.Caption = Tmp
'If it's Line4 then set Text1's text
If iCount = 4 Then Text1 = Tmp
Loop
Close #1
-
Or try to load all lines into an array and refer to them later:
Code:
Option Explicit
Private Sub Command1_Click()
Dim FF As Integer: FF = FreeFile
Dim MyArray() As String
Dim inCount As Integer: inCount = 1
Open "C:\windows\desktop\test.txt" For Input As #FF
Do While Not EOF(FF)
ReDim Preserve MyArray(inCount)
Line Input #FF, MyArray(inCount)
inCount = inCount + 1
Loop
Close #FF
'//First Line is in MyArray(1)
End Sub