VB 6.0 - Error 52, Bad file name or number VB6

Asked By Mike on 22-Nov-10 12:38 PM
We have a DLL which has been running solid for years.  We had to modify a function in one part of the DLL and now an unrelated function is throwing the above error when we attempt to:

intFileNum = FreeFile()
Open strFileName For Binary Access Read As #intFileNum

Suddenly, this part of the DLL can't open the file.  Other than the unrelated function, nothing has changed.  Have checked permissions, no change to the network or servers, the file it is attempting to open exists and can be opened from the Start -> Run menu item in Windows.  I have tried changing the function signature by adding an optional parameter, have unregistered and re-registered the DLL...everything I I can possibly think of I have tried.  I'm out of ideas.  Does anybody have suggestions of why this has suddenly gone bad for me?

Thanks for reading this,
Mike
Venkat K replied to Mike on 22-Nov-10 10:00 PM

This error occurs if a statement in vb refers to a file with a file number or file name that is:

  • Not specified in the Open statement or was specified in an Open statement, but has since been closed.

    Specify the file name in an Open statement. Note that if you invoked the Close statement without arguments, you may have inadvertently closed all currently open files, invalidating all file numbers.

  • Out of the range of file numbers (1 511).

    If your code is generating file numbers algorithmically, make sure the numbers are valid.

Try to debug the code and check at which statement you are getting the error. Or you are trying to open a file that is not physically available. So you need to place some files at a fileshare or some where to work with this dll.

Thanks

Mike replied to Venkat K on 23-Nov-10 10:25 AM
Found the problem -- had to unregister the DLL, stop component services on the http://www.vbforums.com/showthread.php?t=633634#, delete the component from component services, add the fresh DLL as unregistered component, and restart component services. Only took two days to figure this out!

Thanks for your help,
Mike