roscoe
Well-known Member
- Joined
- Jun 4, 2002
- Messages
- 1,046
- Office Version
- 365
- Platform
- Windows
- MacOS
I have code that imports the contents of a text file. On rare occasions it fails. Here's the code in question (please ignore typos as they are not relevant to the problem but merely reflect my poor typing skills):
Set urlObj = CreateObject("Scripting.FileSystemObject")
Set cHTML = urlobj.getfile(TextFileName)
Set cinfo = cHTML.OpenAstextStream(1,0)
Note: I stole this code from someone else who was reading in html files and until now has worked fine for non-HTML text files (if that mattered at all). In fact I use it in multiple locations (i.e. opening other text files) and it has NEVER failed (assuming the file actually exists).
The issue: On rare occasions (randomly and unable to reproduce "on command") the code just stops at the second line above relative to a specific file. I've found that if I select "debug" to open the code I can then just hit F5 (without doing anything else) and it will continue normally. More often than not it doesn't fail and continues through this step normally.
What I have observed is that the the specific file being opened (i.e the one that is failing) is very large (>750,000 lines). I suspect that because of the size it takes a smidge longer than normal for the operating system (OS) to process the line and therefore is subject to failing. I'm wondering (seeking your wise guidance here) if there's some code I can add that will maybe add a few "beats" to the code around this line to allow the OS to keep up and prevent the random fails.
Thanks in advance!
Set urlObj = CreateObject("Scripting.FileSystemObject")
Set cHTML = urlobj.getfile(TextFileName)
Set cinfo = cHTML.OpenAstextStream(1,0)
Note: I stole this code from someone else who was reading in html files and until now has worked fine for non-HTML text files (if that mattered at all). In fact I use it in multiple locations (i.e. opening other text files) and it has NEVER failed (assuming the file actually exists).
The issue: On rare occasions (randomly and unable to reproduce "on command") the code just stops at the second line above relative to a specific file. I've found that if I select "debug" to open the code I can then just hit F5 (without doing anything else) and it will continue normally. More often than not it doesn't fail and continues through this step normally.
What I have observed is that the the specific file being opened (i.e the one that is failing) is very large (>750,000 lines). I suspect that because of the size it takes a smidge longer than normal for the operating system (OS) to process the line and therefore is subject to failing. I'm wondering (seeking your wise guidance here) if there's some code I can add that will maybe add a few "beats" to the code around this line to allow the OS to keep up and prevent the random fails.
Thanks in advance!