Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28434 Discussions

VBA can't find second entry point in Fortran DLL file

Ray__Richard
Beginner
893 Views

Hello Everyone,

I have written many Fortran DLL's for Excel VBA, but this one has me really stuck. Fortran version 11.1  using MSVS 2008; Excel 2007 VBA running on Windows 10  (Excel is 32-bit version)

My DLL performs two different tasks

1. Given an acceleration time history (maybe 5-6000 points) compute velocity, and displacement

2. Given the same acceleration time history, computes an earthquake response spectrum via Duhamel's integral. 

Both of these I have done many times in Fortran, and in VBA. And I have used Fortran DLL's before to do this. 

Fortran DLL important parts are shown below

     
Subroutine AVD(Accel,Vel,Disp,VMax,DMax,Gravity,DeltaT,NumAcc)
CDEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS: "AVD" :: AVD
        
      INTEGER*4, INTENT (IN) ::NumAcc
	REAL, INTENT(IN) ::  Accel(20000),Gravity,DeltaT
	REAL, INTENT(OUT) :: Vel(20000),Disp(20000),VMax,DMax

	factor=Gravity*DeltaT/2.0
	factor2=DeltaT/2.0
	Vel(1)=0.0
	Disp(1)=0.0
	do 10 i=2,Numacc
	  Vel(i)=  etc....


 Subroutine EQSpectra(Accel,Xomega,Period,DisMax,VelMax, 
     !                     AccelMax,Zeta,DeltaT,NumAcc,MaxPts)
CDEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS: "EQSpectra" :: EQSpectra
      
      INTEGER*4, INTENT(IN) :: NumAcc,MaxPts
      REAL, INTENT(IN) ::  Accel(20000),Zeta(3),DeltaT
      REAL, INTENT(OUT) :: Xomega(201),Period(201)
	Real, Intent(out) :: DisMax(3,201),VelMax(3,201)
	Real, Intent(out) :: AccelMax(3,201)
       NAccDim =20000
       NumPts=NumAcc*2  
      if (NumPts .gt. MaxPts) then
         NumPts = MaxPts
       end if    etc.......

The VBA code looks like so

Declare Sub EQSpectra Lib "I:\FortranSubs\spectra2018.dll" (Accel As Single, Xomega As Single, _
        Period As Single, DisMax As Single, VelMax As Single, _
        AccelMax As Single, Zeta As Single, DeltaT As Single, _
        NumAcc As Long, MaxPts As Long)

Declare Sub AVD Lib "I:\FortranSubs\spectra2018.dll" (Accel As Single, Vel As Single, Disp As Single, _
        Vel1Max As Single, Disp1Max As Single, Gravity As Single, DeltaT As Single, NumAcc As Long)

.....then later in the VBA, I call the respective routines

 

'compute Velocity, Displacement and write them in
Call AVD(Accel(1), Vel(1), Disp(1), Vel1Max, Disp1Max, Gravity, DeltaT, NumAcc)
For i = 1 To NumAcc
  ActiveSheet.Cells(5 + i, 1) = DeltaT * (i - 1)
  ActiveSheet.Cells(5 + i, 3) = Accel(i)
  ActiveSheet.Cells(5 + i, 4) = Vel(i)
  ActiveSheet.Cells(5 + i, 5) = Disp(i)
Next i

and later, the call to compute spectra....

Zeta(1) = 0#
Zeta(2) = 0.02
Zeta(3) = 0.05
Call EQSpectra(Accel(1), Xomega(1), Period(1), DisMax(1, 1), VelMax(1, 1), AccelMax(1, 1), _
     Zeta(1), DeltaT, NumAcc, MaxPts)

I have been able to successfully run the VBA program past the call to AVD and plot the results on the spreadsheet, however, when I call the EQSpectra routine I get:   Run-time error  '453'

Can't find DLL entry point EQSpectra in I:\FortranSubs\spectra2018.dll

It is obviously finding spectra2018.dll since the AVD routine runs successfully. If anyone has a brilliant suggestion let me know. If not, I will break the routine down to a more simple one and hopefully get it to work correctly, then slowly build it back up again.

Thanks

0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
893 Views

Fixed form is not your friend. How long is that CDEC$ line for EQSpectra?

View solution in original post

0 Kudos
3 Replies
Steve_Lionel
Honored Contributor III
894 Views

Fixed form is not your friend. How long is that CDEC$ line for EQSpectra?

0 Kudos
Ray__Richard
Beginner
893 Views

Steve,  I hereby double your massive salary....The line ends at column....74 !!!  I would not have this problem if I put it on punch cards (yeah, I'm old enough to remember Fortran IV, WatFIV, IBM360, and Amdahl V7 at the old computing center at UMich Ann Arbor, circa 1973).  Let me take off my stupid hat, and redo the Fortran code to free format/ F90 and be happy again. Thanks again.

 

 

 

 

0 Kudos
Ray__Richard
Beginner
893 Views

Problem solved. Sheesh!

0 Kudos
Reply