Results 1 to 10 of 10

Thread: LOOPING fso array txt

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    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.

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    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.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    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.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    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.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: LOOPING fso array txt

    Quote Originally Posted by dilettante View Post
    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.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: LOOPING fso array txt

    Quote Originally Posted by Arnoutdv View Post
    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.

  7. #7
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    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

  8. #8
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,900

    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

  9. #9
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: LOOPING fso array txt

    Quote Originally Posted by luca90 View Post
    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.

  10. #10
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    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
  •  



Click Here to Expand Forum to Full Width