mshox1
asked on
openfile with bad filename or filenumber (e_code = 52) from exec program, but not from debug mode
I encountered a very strange program on a very simple issues.
issues
I want to open a file for output. here is the code
on error go to open_err
ch_output = freefile()
open "my_out.txt" for output as #ch_output
..
open_err:
debug.print err.description & " " & err.number
works perfect, when I run this from debug mode under IDE (F8, etc)
But when I make the exe file. and run it.
it failue on open statuement
it returns: Bad filename or number, err.number = 52
I hope someone can give me some ideas.
thanks
mshox1
issues
I want to open a file for output. here is the code
on error go to open_err
ch_output = freefile()
open "my_out.txt" for output as #ch_output
..
open_err:
debug.print err.description & " " & err.number
works perfect, when I run this from debug mode under IDE (F8, etc)
But when I make the exe file. and run it.
it failue on open statuement
it returns: Bad filename or number, err.number = 52
I hope someone can give me some ideas.
thanks
mshox1
Try replacing open "my_out.txt" to open app.path & "\my_out.txt"
ASKER
MilanKm,
I tried replace the path name to app.path & "\my_out.txt" it failue even in debug mode
(what is the app.path means?)
EDDYKT
I did not close the file otherplace.
I use ch_output = freefile() immediatly before the open statement.
Any other ideals?
I tried replace the path name to app.path & "\my_out.txt" it failue even in debug mode
(what is the app.path means?)
EDDYKT
I did not close the file otherplace.
I use ch_output = freefile() immediatly before the open statement.
Any other ideals?
show us more code
just in case, here what you should do
dim ch_output as integer
on error go to open_err
ch_output = freefile
open "my_out.txt" for output as #ch_output
' do write to file ...
close #ch_output
exit sub ' if it is subroutine
open_err:
debug.print err.description & " " & err.number
just in case, here what you should do
dim ch_output as integer
on error go to open_err
ch_output = freefile
open "my_out.txt" for output as #ch_output
' do write to file ...
close #ch_output
exit sub ' if it is subroutine
open_err:
debug.print err.description & " " & err.number
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
"app.path" stands for application path. It will produce the path where exe or the program is stored. Simply put msgbox app.path on Form Load event
or open app.path & "\my_out.txt" for output as #1
>>You need to tell it the exact path.
i think if you don't specify the path, the file will go to app.path by default
i think if you don't specify the path, the file will go to app.path by default
Error 52 is a duplicate file error.
Either Kill the old file or Open "my_out.txt" For Append As #ch_output
Regards, P1 8-)
Either Kill the old file or Open "my_out.txt" For Append As #ch_output
Regards, P1 8-)
ASKER
To all:
1 Thank you very much for everyone's input. with many help and trying, I finally figured it out:
for some reason, it works if I use the 'full pathname' in open statement
(for output, or for append).
what I mean full-pathname include foldername\filename
2. Or just hard code a file name like "test.out" for output.
3. If I use the variable name, such as
dim filename as string
filename = "output.txt", it will not works (in exe mode, but work in debug mode)
unless I change the filename (either read from the ini file, or command line) to
full path name.
I am going to close this discussion, and want to share what I finally discovered results.
welcome any comments.
regards,
mshox1
1 Thank you very much for everyone's input. with many help and trying, I finally figured it out:
for some reason, it works if I use the 'full pathname' in open statement
(for output, or for append).
what I mean full-pathname include foldername\filename
2. Or just hard code a file name like "test.out" for output.
3. If I use the variable name, such as
dim filename as string
filename = "output.txt", it will not works (in exe mode, but work in debug mode)
unless I change the filename (either read from the ini file, or command line) to
full path name.
I am going to close this discussion, and want to share what I finally discovered results.
welcome any comments.
regards,
mshox1
i.e.
close #ch_output