Silverfrost Forums

Welcome to our forums

Problem using CURDIR@ in DLL called by VB

27 Sep 2011 6:26 #9028

Hi,

I have spent most of 3 days tracking down a problem (no, I'm not a professional programmer) that occurred when I tried to call a Fortran DLL from Visual Basic. It appears the problem is caused by using CURDIR@ in the Fortran.

The following Fortran works fine when called from VB: …. Character (LEN=300):: FN_Input …. FN_input = “hardwired path to test.csv” Open(unit=IR, file = FN_Input, status='old', err=999) ….

Replacing the above code with: …. Character (LEN=300):: FN_Input CHARACTER (LEN=256)::CURDIR@ …. FN_Input = Trim(CURDIR@()) // '\test.csv' Open(unit=IR, file = FN_Input, status='old', err=999) …. Results in Excel crashing as soon as the open command is executed

However, if I call the same code from Fortran rather than VB, it executes fine as far as I can tell (i.e. it reads the contents of the file)

Am I doing something obviously wrong?

Thanks, Kent

27 Sep 2011 7:55 #9029

SORRY,

I'm pretty sure my own stupidity caused the problem so you can delete this topic.

I still can't understand why the error trapping in the FORTRAN read statement didn't properly ID my real problem, but I don't want to spend more time figuring out how I screwed that up too.

Kent

28 Sep 2011 12:38 #9031

The use of 'IOSTAT=' can sometimes be helpful in these cases. I've taken an error report I use and listed it below:

      EXTERNAL  FORTRAN_ERROR_MESSAGE@
      CHARACTER MESSAGE*64, program_MODULE*64
!
Open (unit=IR, file = FN_Input, status='old', iostat=err_code) 
if (err_code /= 0) then
      CALL FORTRAN_ERROR_MESSAGE@ (err_code, MESSAGE)
      WRITE (*,1001) err_code,FN_Input,IR,program_MODULE,trim(MESSAGE)
 1001 FORMAT (' ***** FILE ACCESSING ERROR *****'/                      &
              ' status : ',I0/                                          &
              ' file   : ',A/                                           &
              ' unit   : ',I0/                                          &
              ' module : ',A/                                           &
              ' type   : ',A)
   goto 999
end if
28 Sep 2011 12:25 #9033

Thanks, John

Out of curiosity, do you know why Excel crashed when the Fortran tried to read a non-existent file? Since I had an 'err=999' statement I would have thought the Fortran would just trigger the code I had at 999 (a write statement followed by a 'stop') and the exit would have been more graceful as well as more informative

Thanks, Kent

Please login to reply.