[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 470
  • Last Modified:

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

0
mshox1
Asked:
mshox1
  • 3
  • 3
  • 2
  • +2
1 Solution
 
EDDYKTCommented:
did you close the file somewhere?

i.e.

close #ch_output
0
 
MilanKMCommented:
Try replacing open "my_out.txt" to open app.path & "\my_out.txt"
0
 
mshox1Author Commented:
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?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
EDDYKTCommented:
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
0
 
lunchbyteCommented:
You do not have a valid path.

You need to tell it the exact path. Right now it assume the file exists in the last used folder so when you switch to app.path its now in the folder that contains your code for design time.

Try this to keep it simple for now.

open "c:\my_out.txt" for output as #ch_output
0
 
MilanKMCommented:
"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
0
 
MilanKMCommented:
or open app.path & "\my_out.txt" for output as #1
0
 
EDDYKTCommented:
>>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
0
 
P1Commented:
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-)
0
 
mshox1Author Commented:
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
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now