|
-
Jun 7th, 2000, 10:14 PM
#1
Thread Starter
Hyperactive Member
I need to take a text file, read it line by line, and put certain lines into an array...
I need some help on the reading line by line part...
Can anyone steer me in the right direction? I don't need to read it all into an array, just 1 line at a time, and if the line meets certain criteria, put THAT LINE in an array...(I can handle the "if it meets certain criteria" part...)
Thanks!!
-
Jun 7th, 2000, 10:42 PM
#2
Fanatic Member
Something along the lines of.
Code:
Open "myTxt.txt" For Input As #1
Do While Not Eof(1)
Line Input #1, myVariabe
Loop
Close #1
Hope that helps.
Iain, thats with an i by the way!
-
Jun 7th, 2000, 11:37 PM
#3
Hyperactive Member
Or you could put it directly into a Perfect Fitting array like so:
Dim ln$(10)
lines = 0: Erase ln$: maxlines = 10:
Do While Not EOF(1)
Call createnextline((maxlines))
Line Input #1, ln$(lines)
ln$(lines) = RTrim$(ln$(lines))
Loop
Public Sub createnextline(maxlines)
lines = lines + 1
If lines + 20 >= maxlines Then
maxlines = lines + 40
ReDim Preserve ln$(maxlines)
End If
End Sub
Good luck...
-
Jun 7th, 2000, 11:51 PM
#4
_______
"or"
or.....'the results are what you want.
'list box is only for a visula of what is happening
'you can remove it when satisfied you get what
'you are after
Option Explicit
Option Compare Text
Dim filesys, txtStream As Object
Private Sub Form_Load()
Dim myArr() As Variant
Dim i As Integer
Set filesys = CreateObject("Scripting.FileSystemObject")
Set txtStream = filesys.openTextFile("C:\my documents\x.txt")
Do Until txtStream.atendofstream
i = i + 1
ReDim Preserve myArr(1 To i) As Variant
myArr(i) = txtStream.readline
myArr(i) = Trim(myArr(i))
If myArr(i) = "Whatever line you want to look for" Then
List1.AddItem myArr(i)
End If
Loop
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|