Link to home
Start Free TrialLog in
Avatar of abnc
abnc

asked on

Run-time Error 52 When Clicking on Registered File Type to Start App

I have an application that keeps giving the following error on all machines other than my development machine when I click on my app's registered file type.

Run-time error 52: Bad file name or number

Clicking on the registered file type on the machine app was developed on works fine. However, on all other machines where program was installed it gives me the run-time error 52 when clicking on the registered file type. If I open the file within my app, I don't get the error on the other machines.

Any suggestions?
Avatar of vinnyd79
vinnyd79

If you are using Command$ , have you tried compiling a message box in to test the value of Command$ on one of the other machines?
Avatar of abnc

ASKER

I placed a msgbox to return the command$ value on the other machines and I get the full path and file name of the file that was clicked on. So that appears to be ok.
Are you using FreeFile to get a file number? If so,make sure the integer is being set to a valid file #.
Actually that would cause a problem on the development machine as well.
ASKER CERTIFIED SOLUTION
Avatar of vinnyd79
vinnyd79

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of abnc

ASKER

I am using FreeFile to get file number. If I trying the Chr$(34) that gives me a Path not found error on development machine, and on the other machines, I still get the 52 error bad file name or number.

Again, the problem only happens when I click on the registered file type. If I start the app first and then open the file, the problem does not occur.

The actual code block where the error is raised appears to be in this code below:

   Dim sTemp As String, intFileNum as Integer, intTotalCount as Integer
   intFileNum = FreeFile
   Open gstrFileName For Input As #intFileNum
   While Not EOF(intFileNum)
   Line Input #intFileNum, sTemp
   intTotalCount = intTotalCount + 1
   ReDim Preserve g_arrPhotos(intTotalCount)
   g_arrPhotos(intTotalCount - 1) = sTemp
   Wend
   Close
>>when I click on the registered file type

Is it binary format?
Strange, does your file type have muliple actions set? Is "open" set as the default?
Avatar of abnc

ASKER

File being opened is a simple text file that can be opened with Notepad.
do

msgbox gstrFileName

and what is this?
Avatar of abnc

ASKER

I solved the problem, or at least it is working.

gstrFileName was my variable that would grab the Command$ value whenever Command$ has a value. However, there would be quotes (Chr(34)) surrounding the file path and name. For example, "c:\My Documents\Spain Trip.sld" and this caused the Bad File Name or Number error.

When I stripped the quotes off so that gstrFileName would be just c:\My Documents\Spain Trip.sld, with no quotes, then it worked just fine.

Make sense?
This error can be raised if the file name has illegal characters in it:

gstrFileName = "/c:\testit.dat" '<<error 52

And of course always check if the file exists before opening it...

If FileExists(gstrFileName) Then
    'Open file
Else
    MsgBox gstrFileName & " does not exist"
End If

The FileExists function can be found here:
http://vbnet.mvps.org/index.html?code/fileapi/fileexists.htm

Good Luck!
Avatar of abnc

ASKER

I have awarded the points to vinnyd79 since his responses got me thinking about double checking what the Command$ was returning and I noticed the problem of the quotes being passed into the variable holding the path location and filename.