Solved

Handle file not found in VB6

Posted on 2011-09-20
2
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

717 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