Recently i created a program that involved Fortran and excel. The main solving was handled by the Fortran and excel provided the GUI.
I know many people search for this so here’s the small example that i worked on before going to the main program.
I used gfortran as Fortran compiler and Excel 2003 for the GUI.
Fortran program accepts and array and does some calculation and returns the values back to excel.
The excel VBA code, call the Fortran dll and then the results form the dll call are posted in excel cells.
Here’s the Fortran program
Subroutine FortranDLL( Array1, upbound )
Implicit None
! …argument declarations
Integer :: upbound
Integer :: Array1(1:upbound)
! Local variables
Integer :: i
do i=1,upbound
Array1(i)=288.16-0.0065*Array1(i)
end do
End Subroutine FortranDLL
It was compiled with the following options.
gfortran -mrtd -fno-underscoring -shared -o fortrandll.dll fortrandll.f90
And here’s what I did in the excel.
Declare Sub fortrandll Lib "C:\TEMP\fortrandll.dll" (ByRef Array1 As Double, ByRef upbound As Long)
Sub Button1_Click()
Dim II As Long
Dim test(10) As Double
II = 11
Call fortrandll(test(1), II)
Range("a1").Value = test(1)
Range("a2").Value = test(2)
Range("a3").Value = test(3)
Range("a4").Value = test(4)
Range("a5").Value = test(5)
Range("a6").Value = test(6)
Range("a7").Value = test(7)
Range("a8").Value = test(8)
Range("a9").Value = test(9)
Range("a10").Value = test(10)
End Sub
Will post more in coming weeks. Maybe a full fledged excel application using a fortran dll.
I think ARRAY1 should be declared double precision in the Fortran subroutine (not integer).
Thanks for the example!
LikeLike
Pingback: How to create Fortran DLL in Visual Studio with Intel Fortran compiler « SukhbinderSingh.com
Pingback: Fortran DLL and Excel « SukhbinderSingh.com
Pingback: 2012 in Review « SukhbinderSingh.com
Pingback: Top 5 posts | SukhbinderSingh.com
Pingback: Few Toy Programs to Mesh Excel and Fortran together | SukhbinderSingh.com
I like what you guys are usually up too. Such clever work and exposure!
Keep up the fantastic works guys I’ve included you guys to my own blogroll.
LikeLike
Oh my goodness! Amazing article dude! Thanks, However I am going
through problems with your RSS. I don’t know why I cannot join it.
Is there anybody getting similar RSS issues? Anyone that knows the answer will you kindly respond?
Thanks!!
LikeLike
I just got a error message saying ‘file can not be found’.
LikeLike
Hi, I got error message too, the message is
‘453’ Runtime error occured.fortrandll’s could not find in C:\TEMP\FortanDLL.dll
But i put into Fortrandll.dll in C:\TEMP
My enviroment is Visual studio 2015 32bit, and Fortran Intel compiler 18.0 32 bit.
Please reply my problem Thanks.
LikeLike
Please check if the name is correct, there might be an issue of name mangling. Also you can check this link https://docs.google.com/present/view?id=dfp3wrf8_275mz3r6xgh&autoStart=true&loop=true for building fortran dll with intel fortran
LikeLike
Thanks, it’s solved. and i have one more question, when i run this program, i confirmed value is 288.160003662109. is this correct ?? i put ‘1’ into a1 cell then 288.160003662109 get out. i don’t under stand when i checked equation, it’s incorrect value.
LikeLike