Topic: dlgsavefile mask

I'm confused about how dlgsavefile is used in Simply Fortran.  In my program, I have the following:

if(dlgsavefile(OutputFile,"*.csv","*.csv","Output Data File")) then
  OPEN(4,FILE=trim(OutputFile),STATUS="REPLACE",ACTION="WRITE")
  write(*,*) "Output Data File is: ",Trim(OutputFile)
else
  write(*,*) "No output file selected."
endif

When the dialog box opens, no CSV files are listed even though they exist in the folder.  If I click the "All Files" drop-down, I see them.  Also, I expected a new file created with the "*.csv" mask to be a CSV file, but it defaults to no file extension unless you're choosing a file from the folder.

dlgopenfile shows the CSV files per the "*.csv" mask, but I don't expect it was intended for typing a nonexistent file in.

Is this a bug in the dlgsavefile?  I'm using Windows 7.  Can I just use dlgopenfile for both opening existing files and either saving over existing files or creating a new file?

Re: dlgsavefile mask

Hmm...I changed it to dlgopenfile and it did the same thing.  Is there an issue with using the command twice in a row in the program?  The first time it shows the CSV files, but regardless of the 2nd time being dlgopenfile or dlgsavefile, it doesn't list the CSV files in the folder.  Is there another command I need to execute between the dialog box call-outs?

If(dlgopenfile(InputFile,"*.csv","*.csv","Input Data File")) then
  OPEN(3,FILE=trim(InputFile),ACTION="READ")
  write(*,*) "Input Data File is: ",Trim(InputFile)
else
  write(*,*) "No input file selected."
endif
if(dlgsavefile(OutputFile,"*.csv","*.csv","Output Data File")) then
  OPEN(4,FILE=trim(OutputFile),STATUS="REPLACE",ACTION="WRITE")
  write(*,*) "Output Data File is: ",Trim(OutputFile)
else
  write(*,*) "No output file selected."
endif

Re: dlgsavefile mask

Don,

Are you initializing the filenames to anything?  I'm guessing that the variable OutputFile hasn't been set to, for example, all spaces, and Windows is subsequently restricting the listed files to those that match the presumably unintended contents of OutputFile.

If you initialize OutputFile, does it work differently?

Jeff Armstrong
Approximatrix, LLC

Re: dlgsavefile mask

No I didn't initialize the contents of either InputFile or OutputFile.  Adding InputFile = " " and OutputFile = " " took care of it.  Thanks so much!

(They're defined as *255.  I don't believe it always did, but a "?" was showing up in the "File name" box of the dialog.  Deleting the ? didn't change the listing.)

Re: dlgsavefile mask

One more thing...
To solve my other issue of dlgsavefile not automatically adding ".csv" to the end of a typed-in filename, I used the following line:

  if(ACHAR(LEN_TRIM(OutputFile)-3)/=".") OutputFile=TRIM(OutputFile)//".csv"

Is this how it's done or is there a common, more robust way to go?

Re: dlgsavefile mask

Don,

No, there isn't a better way.  Windows doesn't enforce the extension, so the programmer has to do it manually by checking and adding it to the returned filename if necessary.

Jeff Armstrong
Approximatrix, LLC

Re: dlgsavefile mask

Just an FYI in case someone were to try my "if" statement.  As it turns out, that didn't work in my case like I thought it did.  "ACHAR(LEN_TRIM(OutputFile)-3" returned ">" instead of "."  The following is what I wound up using, and it seems to work fine...

if(Outputfile(LEN_TRIM(OutputFile)-3:LEN_TRIM(OutputFile)-3)/=".") OutputFile=TRIM(OutputFile)//".csv"