Results 1 to 5 of 5
  1. #1
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83

    Err 7-out of memory, read text file

    I am trying to get the total number of lines in a text file with the code below (The file is about 190,577kb) because i create a progress bar for when I am actually reading the lines with my program so the user knows how far along it is. Is there a better way to read the lines where I do not get this error or is there a better approach to size the incremental widths of my progress bar? Edit: filePathnew is the files that is 190,577kb



    Code:
    iFileNo = FreeFile
                Open filePathNew For Binary As iFileNo
                strFile = Space(LOF(iFileNo)) 'Set file buffer size
                Get iFileNo, , strFile 'Load the text
                Close iFileNo
                'The array holds the file, one line per element
                strArray = Split(strFile, vbNewLine)
    Last edited by dssrun; 11-28-2011 at 03:44 PM.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    well trying to throw the number of bytes that's in a 190,000K text file into a vb array is probably not a good idea.

    I would say a better idea would be to import the file into an access table using transfertext and issuing a domain count on the dataset. That would use about 99% less memory than you're using now.

    furthermore, on a side note here, I believe the maximum size that notepad can handle as a stand-alone program is about 150,000K of ascii text, if that.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    This is what I use to count the lines in a text file for a progress bar. I open the text file and remove any blank lines (or garbage) at the top & bottom of the file before running the code:

    Code:
    <snip>
       Dim FF As Integer
       Dim LineCount As Long
       Dim inpStr As String  'one line of text
       Dim FileToOpen As String  ' name of file
    
    
       ' Open file for input.
       FileToOpen = "C:\SomePath\theFileName.txt"
       FF = FreeFile
       Open FileToOpen For Input As #FF
    
       If (Err.Number <> 0) Then
          MsgBox "Unable to open file. Aborting!!!"
          Close #FF
          Exit Sub
       End If
    
       ' count lines read
       LineCount = 0
    
       '-----------------------
       Do While Not EOF(FF)
          Line Input #FF, inpStr
          LineCount = LineCount + 1
       Loop
       '-----------------------
       
       Close #FF
    <snip>

  4. #4
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83
    thanks for the reply all. ssanfu, unfortunately i do not have any blank lines.

  5. #5
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by dssrun View Post
    thanks for the reply all. ssanfu, unfortunately i do not have any blank lines.
    No blank lines is good. The point is, get the number of lines by reading the file line by line, not by bytes......

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Memory management, control, mdb file size
    By shubhamgandhi in forum Programming
    Replies: 2
    Last Post: 08-09-2011, 01:33 AM
  2. Replies: 1
    Last Post: 11-05-2010, 04:31 PM
  3. Text File Link
    By pkell658 in forum Import/Export Data
    Replies: 1
    Last Post: 03-23-2010, 04:46 PM
  4. Replies: 2
    Last Post: 02-27-2010, 06:53 AM
  5. Replies: 2
    Last Post: 10-19-2006, 04:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums