Solved

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

Posted on 2004-10-22
171 Views
Last Modified: 2010-05-02
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?
0
Question by:abnc
    13 Comments
     
    LVL 28

    Expert Comment

    by: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?
    0
     

    Author Comment

    by:abnc
    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.
    0
     
    LVL 28

    Expert Comment

    by:vinnyd79
    Are you using FreeFile to get a file number? If so,make sure the integer is being set to a valid file #.
    0
     
    LVL 28

    Expert Comment

    by:vinnyd79
    Actually that would cause a problem on the development machine as well.
    0
     
    LVL 28

    Accepted Solution

    by:
    Do the files have spaces in the name? If so,try enclosing the filename in qoutes:

    Chr$(34) & Command$ & Chr$(34)
    0
     

    Author Comment

    by:abnc
    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
    0
     
    LVL 26

    Expert Comment

    by:EDDYKT
    >>when I click on the registered file type

    Is it binary format?
    0
     
    LVL 28

    Expert Comment

    by:vinnyd79
    Strange, does your file type have muliple actions set? Is "open" set as the default?
    0
     

    Author Comment

    by:abnc
    File being opened is a simple text file that can be opened with Notepad.
    0
     
    LVL 26

    Expert Comment

    by:EDDYKT
    do

    msgbox gstrFileName

    and what is this?
    0
     

    Author Comment

    by:abnc
    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?
    0
     
    LVL 32

    Expert Comment

    by:Erick37
    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!
    0
     

    Author Comment

    by:abnc
    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.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    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…
    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…

    884 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now