-
1st line of file
If i want to read a file from the top to bottom, but i dont wish to use EOF instead i want to read line by line ( i=i+1)
The reason i wish to use that is ...maybe inside a file as below..
ABC
vb3=1
Vb4=2
vb5=3
DEF
Vb1=11
VB2=99
VB5=999
GHI
DEF
Vb51=11
VB2=77
VB5=9993
i want direct read the DEF and treat DEF as the first line of the file...
How do i code it?
please help
-
Re: 1st line of file
To read file "line-by-line" you have to either use loop and check while you didn't reach EOF ;) or read entire text into string variable (this is already an overhead) then load array and then loop through array:
Code:
'method 1 (better by far)
Dim strLine$
Open somefile For Input As #1
Do While Not EOF(1)
Line Input #1, strLine
If InStr(1, UCase(strLine), "DEF") > 0 Then
'do something
End If
Loop
Close #1
'method 2 (will also work but isn't necessary best approach)
Dim strText$, arLines() As String, i%
Open somefile For Input As #1
strText = Input(LOF(1), #1)
arLines = Split(strText, vbNewLine)
strText = ""
For i = 0 To UBound(arLines)
strLine = arLines(i)
If InStr(1, UCase(strLine), "DEF") > 0 Then
'do something
End If
Next i
Close #1