I call an array from a Fortran subroutine.
The subroutine runs as it should in a fortan program and gives correct results.
When I call the subroutine in VBA from the fortran dll, I get erroneous results.
No idea what goes wrong I suppose the error is on the VBA side because the program gives the correct results.
In the spreadsheet =Max_Min(L, P1, P2, P3, P4, a1, a2, a3, t)
gives the following result: 141.00 -120.00 2.00 5.6 6.00 7.8
Whereas running the progam gives the following correct results:
141.51 -120.27 9.90 9.90 6.00 7.80
This is very strange.
ar(1) and ar(2) seem to be transformed in integers
ar(3) and ar(4) are erroneous
ar(5) and ar(6) seem to be correct
Declare PtrSafe Sub MaxMin Lib "D:\fortran_projects\kraanbaan_excel\kraanbaan_dll.dll" (ByVal L As Double, _
ByVal P1 As Double, ByVal P2 As Double, ByVal P3 As Double, ByVal P4 As Double, ByVal a1 As Double, _
ByVal a2 As Double, ByVal a3 As Double, ByVal t As Double, ByRef ar As Double)
Function Max_Min(L As Double, P1 As Double, P2 As Double, P3 As Double, P4 As Double, a1 As Double, _
a2 As Double, a3 As Double, t As Double)
Dim ar(1 To 6) As Double
'Call Fortran
MaxMin L, P1, P2, P3, P4, a1, a2, a3, t, ar(1)
Max_Min = ar
End Function