-
Sep 12th, 2020, 06:38 AM
#1
Thread Starter
PowerPoster
LOOPING fso array txt
part of code:
Code:
...
MYFILEPATH = "C:\file.txt"
Set SOURCEFILE = FSO.OpenTextFile(MYFILEPATH, ForReading)
MYFILETEXT = SOURCEFILE.ReadAll
SOURCEFILE.Close
....
how to loop MYFILETEXT , and retrive line by line the row of txt file?
Last edited by luca90; Sep 12th, 2020 at 11:43 AM.
-
Sep 12th, 2020, 06:55 AM
#2
Re: LOOPING fso array txt
Code:
Dim fID As Integer
Dim sLine As String
fID = Freefile
Open “C:\somefile.txt” For Input As #fID
Do Until Eof(fID)
Line Input #fID, sLine
Loop
Close #fID
Last edited by Arnoutdv; Sep 13th, 2020 at 03:31 AM.
-
Sep 12th, 2020, 09:53 AM
#3
Re: LOOPING fso array txt
Works just as described in the manual:
Code:
Dim TextStream As Scripting.TextStream
Set TextStream = FSO.OpenTextFile("Some.txt", _
ForReading, _
Create:=False, _
Format:=TristateFalse)
With TextStream
Do Until .AtEndOfStream
Print .ReadLine()
Loop
.Close
End With
FSO usually isn't the way to go though. Companies have stopped blocking the Scripting Runtime for security reasons so much any more but it remains pretty slow and awkward in general.
-
Sep 12th, 2020, 10:10 AM
#4
Re: LOOPING fso array txt
BTW:
Native Line Input statements treat CRLF or CR as line delimiter and respect Ctrl-Z as EOF.
The TextStream.ReadLine() method treats CRLF or LF as line delimiter with no respect for Ctrl-Z which is treated as just another character.
-
Sep 12th, 2020, 10:15 AM
#5
Thread Starter
PowerPoster
Re: LOOPING fso array txt
Originally Posted by dilettante
BTW:
Native Line Input statements treat CRLF or CR as line delimiter and respect Ctrl-Z as EOF.
The TextStream.ReadLine() method treats CRLF or LF as line delimiter with no respect for Ctrl-Z which is treated as just another character.
good explain tk.
-
Sep 12th, 2020, 03:49 PM
#6
Thread Starter
PowerPoster
Re: LOOPING fso array txt
Originally Posted by Arnoutdv
Code:
Dim fID As Integer
Dim sLine As String
fID = Freefile
Open “C:\file.txt” For Input As #fID
Do Until Eof(fID)
Line Input #fID, sLine
Loop
Close #fID
Please can you change Path in
MYFILEPATH = "C:\file.txt"
The original contain reserved info.
Tks
Last edited by FunkyDexter; Sep 13th, 2020 at 05:49 AM.
-
Sep 13th, 2020, 03:32 AM
#7
Re: LOOPING fso array txt
Hahaha, you quoted my posted.
Now you have to change your post.
Thought I don’t see what’s so special about the filename
-
Sep 13th, 2020, 05:50 AM
#8
Re: LOOPING fso array txt
Have edited the file path. I'm not sure what was sensitive about it either but <shrug> should be ok now.
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
-
Sep 13th, 2020, 07:08 AM
#9
Re: LOOPING fso array txt
Originally Posted by luca90
Please can you change Path in
MYFILEPATH = "C:\file.txt"
The original contain reserved info.
Tks
So you couldn't do that yourself? Also note that you should not be placing your files in the root of the drive.
-
Sep 13th, 2020, 03:44 PM
#10
Re: LOOPING fso array txt
It was addressed to me.
I copied the original path from the original first post.
Somehow Luca made a mistake and wanted all posts to be modified
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
|