Gary Davies
New Member
- Joined
- Jul 28, 2003
- Messages
- 8
I am willing to hire someone for a few hours of help if necessary. I'm tired of beating my head and getting nowhere. I need to get this working so I can do productive work.
I need to get some simple example fortran program functions working as functions I can call from excel or an excel macro. Once the examples work, I should be able to take it from there with more complex programs. I am using gfortran as my compiler, Windows Vista, excel 2003. I have successfully gotten the integer math function "intadd" working but the real number function "numadd" gives me a "2 E308" answer when I use the function in excel.
fortran file test1.f95:
function intadd(i,j)
intadd=i+j
end
fortran file test2.f95:
function numadd(a,b)
real*8 a,b
numadd=a+b
end
batch program make1.bat to compile test1.f95:
gfortran -s -shared -mrtd -o test1.dll test1.def test1.f95
batch program make2.bat to compile test2.f95:
gfortran -s -shared -mrtd -o test2.dll test2.def test2.f95
excel vba macro:
Declare Function intadd Lib "c:\g77\test1.dll" (i As Long, j As Long) As Long
Declare Function numadd Lib "c:\g77\test2.dll" (a As Double, b As Double) As Double
Function gdfct1(i, j)
gdfct1 = intadd(i, j)
End Function
Function gdfct2(a, b)
gdfct2 = numadd(a, b)
End Function
The gdfct1 works correctly when called from a cell in the worksheet, as does putting "=intadd(3,4)" in a cell in the worksheet.
The gdfct2 gives me a "#value" error in the worksheet, and putting "numadd(4.4,5.5)" gives me the "2 E308" value.
I've tried upper case function names and a few other things I've read on line. Doesn't seem to be a path issue since the intadd function works fine. Maybe variable declaration types, which I am not good with?
thanks for any help you can give me.
I need to get some simple example fortran program functions working as functions I can call from excel or an excel macro. Once the examples work, I should be able to take it from there with more complex programs. I am using gfortran as my compiler, Windows Vista, excel 2003. I have successfully gotten the integer math function "intadd" working but the real number function "numadd" gives me a "2 E308" answer when I use the function in excel.
fortran file test1.f95:
function intadd(i,j)
intadd=i+j
end
fortran file test2.f95:
function numadd(a,b)
real*8 a,b
numadd=a+b
end
batch program make1.bat to compile test1.f95:
gfortran -s -shared -mrtd -o test1.dll test1.def test1.f95
batch program make2.bat to compile test2.f95:
gfortran -s -shared -mrtd -o test2.dll test2.def test2.f95
excel vba macro:
Declare Function intadd Lib "c:\g77\test1.dll" (i As Long, j As Long) As Long
Declare Function numadd Lib "c:\g77\test2.dll" (a As Double, b As Double) As Double
Function gdfct1(i, j)
gdfct1 = intadd(i, j)
End Function
Function gdfct2(a, b)
gdfct2 = numadd(a, b)
End Function
The gdfct1 works correctly when called from a cell in the worksheet, as does putting "=intadd(3,4)" in a cell in the worksheet.
The gdfct2 gives me a "#value" error in the worksheet, and putting "numadd(4.4,5.5)" gives me the "2 E308" value.
I've tried upper case function names and a few other things I've read on line. Doesn't seem to be a path issue since the intadd function works fine. Maybe variable declaration types, which I am not good with?
thanks for any help you can give me.