ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Reading Textfile into a variable (https://www.excelbanter.com/excel-programming/294804-reading-textfile-into-variable.html)

Seth[_3_]

Reading Textfile into a variable
 
Hi,

I am trying to use the Input function to read the
contents of a text file into a variable. The text file
is very large, and I keep getting the same message
everytime I try to run code that I know works on other
text files (they are smaller):

"Input past end of file"

Here is the code:
____________________________________________
FF = FreeFile ' get the next free file in line

Open SourceFile For Input As FF ' Opens the text file
stream
lChars = LOF(FF) ' lChars is a LONG varaible

AllText = Input(lChars, FF) ' Loads the textfile into
the AllText variable (AllText is a string variable and i
tried Variant too with the same result)

Close FF
_______________________________________________

The number of characters in the text file is 2,685,277.
When the code is executed i get "Input past end of file".

If I force the number of characters to a lower number, it
all works fine.

Any thoughts on what is going on, and if there is a
workaround?

Thanks,

Seth

Rob van Gelder[_4_]

Reading Textfile into a variable
 
Try: Open SourceFile For Binary As FF

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Seth" wrote in message
...
Hi,

I am trying to use the Input function to read the
contents of a text file into a variable. The text file
is very large, and I keep getting the same message
everytime I try to run code that I know works on other
text files (they are smaller):

"Input past end of file"

Here is the code:
____________________________________________
FF = FreeFile ' get the next free file in line

Open SourceFile For Input As FF ' Opens the text file
stream
lChars = LOF(FF) ' lChars is a LONG varaible

AllText = Input(lChars, FF) ' Loads the textfile into
the AllText variable (AllText is a string variable and i
tried Variant too with the same result)

Close FF
_______________________________________________

The number of characters in the text file is 2,685,277.
When the code is executed i get "Input past end of file".

If I force the number of characters to a lower number, it
all works fine.

Any thoughts on what is going on, and if there is a
workaround?

Thanks,

Seth





All times are GMT +1. The time now is 03:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com