Silverfrost Forums

Welcome to our forums

Opening a file with Windows using FTN95

27 Aug 2010 12:44 #6845

I need to open three different files in a Windows program I'm writing, using WINAPP and including <windows.ins> on a WinXP system. It is a fixed-format FORTRAN program file called PARTSPROG.for .

Using an example from the HELP file, I'm able to open all three successfully. But a lot of windows and mouse clicks are involved for each one, and it gets tedious. I've listed the present code at the bottom of this post. Is there a way I can streamline this?

Presently when I run the program:

  • A small window appears with the title 'Select Parts List' and one menu heading, 'File'.
  • I click on 'File', and one subheading appears, 'Open'.
  • I click on 'Open', and the usual Windows file-selection window appears, letting me navigate thru paths, select the file, and click the OPEN button.
  • When I click that OPEN button, the Windows file-selection window disappears, as expected. But the small window with the 'Select Parts List' title is still there.
  • If I then click on the X at the upper right corner of this small window, the small window vanishes, and the program moves on the the next section, which uses similar code to open the next file I need.

That works, but is tedious, and there's a risk that I won't realize that after I click the OPEN button and the file-selection window disappears, the small window I see is still for the file I just opened. I might click on its File manuagain, and then on its Open menu, and re-open the same file I just opened, which I don't want to do.

What I'd rather see the program do, using three similar sections of FTN95 code to open three different files, is:

  • When I start the program, the usual Windows file-selection window appears immediately, with the title 'Select Parts List'.

  • I navigate thru the paths, click on the file I want, and click the OPEN button. The file-selection window disappears.

  • A new File-selection window appears (I might put it in a different location on the screen, or with a different color) with the title 'Now select the 2nd file'.

  • That lets me navigate to the second file, click on it, and click the OPEN button. That file-selection window disappears.

  • A third file-selection window appears to let me open the third file, etc.

Is there a way I can get my program to operate in a streamlined way like that?


The code I'm presently using is:

  PROGRAM MYPARTS
  WINAPP
  include <windows.ins>
  CHARACTER*250 ABPartsListNm,filenm
  COMMON/FileNames/filenm
  EXTERNAL getfilenm
  .
  .
  filenm=''
  i=winio@('%ca[&amp;Select Parts List]&amp;')
  i=winio@('%mn[&amp;File[&amp;Open]]','FILE_OPENR',filenm,getfilenm)
  ABPartsListNm=filenm
  OPEN(3,FILE=ABPartsListNm,ACTION='READ')
  .
  .

<two more sections of similar code with different filenames> . . STOP END C INTEGER FUNCTION getfilenm() CHARACTER*250 filenm COMMON/FileNames/filenm i=winio@('%ws %`bt[OK]',filenm) getfilenm=1 END

27 Aug 2010 7:24 #6847

I think you should use get_filtered_file@. The code may be similar to the following (within your main programme at the beginning):

      integer*4     i
      character*40  title(3),text(3),extens(3)
      character*120 path,curdir@,string,my_file_1(3)

      path   = curdir@
      string = curdir@
      call append_string@(string,'\\*.dat')
      title(1)  = 'Select parts #1'
      text(1)   = 'File #1'
      extens(1) = 'dat'
      i = 1
      call get_filtered_file@(title,string,path,text,extens,i,1L)
      if (string .ne. ' ') then
        my_file(1) = string
c
c
c
      end if

      string = curdir@
      call append_string@(string,'\\*.dat')
      title(2)  = 'Select parts #2'
      text(2)   = 'File #2'
      i = 1
      call get_filtered_file@(title,string,path,text,extens,i,1L)
      if (string .ne. ' ') then
        my_file(2) = string
c
c
c
      end if
c
c
c

Regards, Wilfried

27 Aug 2010 9:14 #6851

Thank you, Wilfried, I will try this!

29 Aug 2010 12:21 #6852

Hi Little-Acorn,

Wilfried has pointed out to you the alternative system using a subroutine call instead of a standard call-back which means that you do not need a persistent window. You still need to get the 3 separate files. Why not open just one file which contains the names of all the other files you want to open?

Alternatively, if the three files are linked in some way, why not get the basic name once, and work out the other names as you go? One way of doing this would be to have the same file name, but different extensions e.g.

oaktree.dat oaktree.prt oaktree.ext

or make the file names relate to each other in a systematic way, e.g.

bigoak_1.dat bigoak_2.dat bigoak_3.dat

if the extension is meaningful. Remember that you can even change the subdirectory as well when doing this.

Another post covers a routine for getting multiple files in one go.

Eddie

Please login to reply.