Solved

Handle file not found in VB6

Posted on 2011-09-20
2
218 Views
Last Modified: 2012-05-12
I have a situation in a VB6 program in which I want the program to wait for a specific filename to appear in a folder.  I was thinking of having it repeatedly try to open that file, and then put an "on error goto" statement to make it not blow up, and possibly a timer so that it doesn't sit there and spin continually.  The first "on error goto" command works OK, but subsequent calls to it cause it to throw the "file not found" dialog.  So...how do I reset the error handler so that it works for what I need it to do?  TIA.
Sub WaitForFile()
   fIntFile = FreeFile
   
NoFileAvailable:
   Err.Clear
'Handle file not found errors
   On Error GoTo NoFileAvailable


Open strIntFileName For Input As #fIntFile
   
End Sub

Open in new window

0
Comment
Question by:thomsone
2 Comments
 
LVL 7

Accepted Solution

by:
shaydie earned 500 total points
ID: 36569651
Why not just check for its existence rather than try to open it and generate an error?
something like
if dir(filename) = "" then
0
 

Author Closing Comment

by:thomsone
ID: 36569683
Great idea!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question