0

I make use of the typical INPUT and LOF statement to read in large textiles. Some text file are 100MB and gets read in with no problem. Other smaller files give the error as in the title.

VBA (Excel)

'Open file and read all lines in as strings

    FileName = SumOutPath & "\" & WRYMPf & "SUM.OUT"
    Erase v
    sFile = FileName
    Open sFile For Input As #1
    sWhole = Input$(LOF(1), 1) 'This is where the error occurs some of the time
    Close #1
    v = Split(sWhole, vbNewLine)

Please help.

Thanks Bennie

I checked that the file is not in use and also deleted or added a blank row at the end of the file with no success

Progman
  • 16,827
  • 6
  • 33
  • 48
  • Did you check the encoding of the files - do they differ. Without seeing your files it is nearly impossible to help. – Ike May 18 '23 at 14:15
  • Ike. The text files can be found here https://hydrosol-my.sharepoint.com/:f:/g/personal/bennie_haasbroek_hydrosolconsulting_com/ErQp-KKBbGtMoDHYa3fzPvgBmSPaYAhrXLr9piHAeJx0Mg?e=VhJ6Gj – Bennie Haasbroek May 18 '23 at 14:29
  • See if [this](https://stackoverflow.com/questions/76068736/error62-input-past-end-of-file-on-vba-script-to-search-directory-for-files-cont/76069535#76069535) helps. – Domenic May 18 '23 at 20:10
  • Domenic, thanks for this. Now it reads the whole file into the string but the file seems changed. Should I still use the Split function at the top after the get function. Dim FileNum As Long FileNum = FreeFile FileName = SumOutPath & "\" & WRYMPf & "SUM.OUT" Erase v sFile = FileName Open sFile For Binary Access Read As #FileNum sWhole = Space$(LOF(FileNum)) Get #FileNum, , sWhole Close #FileNum v = Split(sWhole, vbNewLine) – Bennie Haasbroek May 18 '23 at 21:27
  • How has the file changed? – Domenic May 19 '23 at 02:33
  • Yes, you can still use the Split function to get an array of lines. If the line ending is marked by a carriage return and a line feed, use vbNewLine as the delimiter, as you've done. Otherwise, if a line ends with just a line feed, use vbLf as the delimiter. – Domenic May 19 '23 at 02:38

0 Answers0