+ Reply to Thread
Results 1 to 4 of 4

Importing text file. Does entire file get read into memory first?

  1. #1
    Forum Contributor
    Join Date
    07-16-2007
    MS-Off Ver
    Excel 2003 and Excel 2016
    Posts
    178

    Importing text file. Does entire file get read into memory first?

    Hello. I'm importing a rather large delimited text file into Excel. Here's a piece of code I'm using:
    PHP Code: 
    Open myPath myFile For Input As #1
    MsgBox myFile " is open"
            
    Application.StatusBar "Reading records"

    Do While Not EOF(1)
        
    Line Input #1, myStr       
        
    lineCount lineCount 1        
            
    If lineCount 3 Then
                MsgBox myStr
            End 
    If 
    I immediately get the "is open' message, but it seems as though the 'mystr' message doesn't display until the entire 'myfile' is read into memory. Is that what is supposed to happen?

    Thanks.
    Last edited by sumdumgai; 03-10-2016 at 12:01 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    05-14-2012
    Location
    Unknown
    MS-Off Ver
    Unseen
    Posts
    429

    Re: Importing text file. Does entire file get read into memory first?

    Sounds as though you only have one carriage return at the end of data.

    https://msdn.microsoft.com/en-us/lib...(v=vs.60).aspx

    Line Input # Statement

    Reads a single line from an open sequential file and assigns it to a String variable.

    Syntax
    Line Input #filenumber, varname

    The Line Input # statement syntax has these parts:

    Part Description
    filenumber Required. Any valid file number.
    varname Required. Valid Variant or String variable name.

    Remarks

    Data read with Line Input # is usually written from a file with Print #.

    The Line Input # statement reads from a file one character at a time until it encounters a carriage return (Chr(13)) or carriage returnlinefeed (Chr(13) + Chr(10)) sequence. Carriage returnlinefeed sequences are skipped rather than appended to the character string.

  3. #3
    Forum Contributor
    Join Date
    07-16-2007
    MS-Off Ver
    Excel 2003 and Excel 2016
    Posts
    178

    Re: Importing text file. Does entire file get read into memory first?

    Thanks, when I used Gsplit to break up the file, I specified 0x0A, which I believe is line feed. So, are you saying because there is no carriage return (0x0D), or no 0x0D0x0A sequence, at end of each line, the entire file is read into memory?

  4. #4
    Valued Forum Contributor
    Join Date
    05-14-2012
    Location
    Unknown
    MS-Off Ver
    Unseen
    Posts
    429

    Re: Importing text file. Does entire file get read into memory first?

    So, are you saying because there is no carriage return (0x0D), or no 0x0D0x0A sequence, at end of each line, the entire file is read into memory?
    Pretty much, yes. At least, that's what the documentation seems to say.

    Never used Gsplit, so I wouldn't know.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA Importing Text File makes the file longer to load everytime
    By Hudas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-15-2014, 11:26 AM
  2. Importing a data from a text file - user-defined file
    By DaveSev in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2013, 07:02 PM
  3. [SOLVED] importing text file into excel file using macro
    By ananthbulusu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-26-2013, 04:08 PM
  4. Importing a text file to an existing sheet, with a dialog to pick the text file
    By titushanke in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-22-2011, 01:43 PM
  5. Read whole file,Match the headers based on specific condition & write to text file
    By macromaniac in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 06-07-2011, 06:37 AM
  6. read value of strings from a text file and make an excel file.
    By gashforing in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2009, 07:12 AM
  7. Read text from a file with out importing?
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-25-2007, 10:48 AM
  8. [SOLVED] Importing text file, only option to edit existing file
    By smokey99 in forum Excel General
    Replies: 8
    Last Post: 04-26-2006, 04:08 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1