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

Passing one-dimensional array from Fortran dll to Excel 2010

jyeoman
Beginner
323 Views
I am trying to pass a one-dimensional array from a Fortran dll to Excel 2010.

I havesuccessfully run the sample program and I have successfully modified the sample program to return an integer instead of a string.

When I attempt to pass an array, the dll compiles and the VBA code runs. However, I get zeroes in cells A2, A3, and A4 rather than the correct numbers based on the input.

I am using Windows 7, Intel Fortran 11.075, and Excel 2010.

Thanks for any help.

Fortran code:

subroutine FortranCall (r1, num)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:"FortranCall" :: FortranCall
integer, intent(in) :: r1
integer, intent(out) :: num(5)

num = 9
num(1) = r1*100
num(2) = r1*1000

return
end subroutine FortranCall


VBA code:

Private Sub CommandButton1_Click()

Dim r1 As Long
Dim num(5) As Long

r1 = Range("A1")

Call FortranCall(r1, num(5))

Range("A2") = num(2)
Range("A3") = num(3)
Range("A4") = num(4)

End Sub

Module1:

Declare Sub FortranCall Lib "Fcall.dll" (r1 As Long, num As Long)
0 Kudos
1 Reply
jyeoman
Beginner
323 Views

I will answer my own question.

Call FortranCall(r1, num(5)) should be Call FortranCall(r1, num(1))

Now it works.

0 Kudos
Reply