-
Mar 2nd, 2010, 11:26 AM
#1
Thread Starter
Addicted Member
[RESOLVED] "Run time error '52': Bad file name or number" when i open associated text file
i am getting error "Run time error '52': Bad file name or number" when i use this code to open a text file that is accociated with my app.
File association is set up using inno.
when i replace Command$ with "C:\Users\Dave\Documents\dave.cppl" and run it in design mode there is no error.
Code:
Private Sub Form_Load()
Dim DoubleClickedFile As String
Dim sFileText As String
Dim iFileNo As Integer
DoubleClickedFile = Command$
If DoubleClickedFile <> "" Then
DoubleClickedFile = Mid(DoubleClickedFile, 4, Len(DoubleClickedFile) - 3)
Text1.Text = DoubleClickedFile 'to check if the file and path is good
iFileNo = FreeFile
Open DoubleClickedFile For Input As #iFileNo
Input #iFileNo, sFileText
Text1.Text = sFileText
Close #iFileNo
End If
End Sub
-
Mar 2nd, 2010, 11:33 AM
#2
Re: "Run time error '52': Bad file name or number" when i open associated text file
What does Command$ return?
Place break pointer right on that line and you will see the actual value.
Or you can at least print value to debug (Debug.Print DoubleClickedFile).
-
Mar 2nd, 2010, 11:49 AM
#3
Thread Starter
Addicted Member
Re: "Run time error '52': Bad file name or number" when i open associated text file
DoubleClickedFile = Mid(DoubleClickedFile, 4, Len(DoubleClickedFile) - 3)
returns this: \Users\Dave\Documents\dave.cppl"
and DoubleClickedFile returns this: "C:\Users\Dave\Documents\dave.cppl"
i was trying to remove the drive letter but did nit remove the right side quote marks.
Does the drive letter need to be removed of this to work?
-
Mar 2nd, 2010, 11:53 AM
#4
Re: "Run time error '52': Bad file name or number" when i open associated text file
Why are you trying to remove the drive letter?
That is an important part of the file location, and as you are opening the file you want to know the full file location.
-
Mar 2nd, 2010, 11:56 AM
#5
Thread Starter
Addicted Member
Re: "Run time error '52': Bad file name or number" when i open associated text file
I saw the same problem posted elswhere in google and the solution was to remove the drive letter. but this does not work.
-
Mar 2nd, 2010, 11:58 AM
#6
Re: "Run time error '52': Bad file name or number" when i open associated text file
Path must be valid (or complete) or you will get an error.
Solution from that Google search could've related to a different problem though.
-
Mar 2nd, 2010, 12:10 PM
#7
Re: "Run time error '52': Bad file name or number" when i open associated text file
I can't think of any situation like this where removing the drive letter would be a good thing.
Does Command$ actually contain the " character at the start and end?
If so, this should solve it:
Code:
DoubleClickedFile = Command$
If DoubleClickedFile <> "" Then
If Left$(DoubleClickedFile, 1) = """" Then DoubleClickedFile = Mid$(DoubleClickedFile, Len(DoubleClickedFile) -2)
Text1.Text = DoubleClickedFile 'to check if the file and path is good
iFileNo = FreeFile
...
-
Mar 2nd, 2010, 12:22 PM
#8
Thread Starter
Addicted Member
Re: "Run time error '52': Bad file name or number" when i open associated text file
this code returns this: "C:\Users\Dave\Documents\dave.cppl" in text1.text
Code:
Private Sub Form_Load()
On Error Resume Next
Dim DoubleClickedFile As String
Dim sFileText As String
Dim iFileNo As Integer
DoubleClickedFile = Command$
If DoubleClickedFile <> "" Then
'If Left$(DoubleClickedFile, 1) = """" Then DoubleClickedFile = Mid$(DoubleClickedFile, Len(DoubleClickedFile) - 2)
Text1.Text = DoubleClickedFile
iFileNo = FreeFile
Open DoubleClickedFile For Input As #iFileNo
Input #iFileNo, sFileText
Text2.Text = sFileText
Close #iFileNo
End If
End Sub
and this code returns this: pl"
Code:
Private Sub Form_Load()
On Error Resume Next
Dim DoubleClickedFile As String
Dim sFileText As String
Dim iFileNo As Integer
DoubleClickedFile = Command$
If DoubleClickedFile <> "" Then
If Left$(DoubleClickedFile, 1) = """" Then DoubleClickedFile = Mid$(DoubleClickedFile, Len(DoubleClickedFile) - 2)
Text1.Text = DoubleClickedFile
iFileNo = FreeFile
Open DoubleClickedFile For Input As #iFileNo
Input #iFileNo, sFileText
Text2.Text = sFileText
Close #iFileNo
End If
End Sub
either way i get "Run time error '52': Bad file name or number" when i remove "on error resume next"
-
Mar 2nd, 2010, 12:40 PM
#9
Re: "Run time error '52': Bad file name or number" when i open associated text file
Ooops, I missed a parameter:
Code:
If Left$(DoubleClickedFile, 1) = """" Then DoubleClickedFile = Mid$(DoubleClickedFile, 2, Len(DoubleClickedFile) -2)
-
Mar 2nd, 2010, 12:47 PM
#10
Thread Starter
Addicted Member
Re: "Run time error '52': Bad file name or number" when i open associated text file
so my problem was quotes around the file and path.
Thanks, this works.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|