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

Using Fortran dll in VBA of Excel 2010

Hu__Andy
Beginner
338 Views

Hello every one,

I am trying to use Fortran dll in VBA of Excel 2010, but I have a problem now.
I want to get virtual array as returned value, but failed. Here is my code,

* fortran 11

subroutine virtualArrayTest(iv_array,ii)
!DEC$ ATTRIBUTES STDCALL,REFERENCE,DLLEXPORT,ALIAS:"virtualArrayTest"::virtualArrayTest
implicit none
  integer,intent(out):: ii
  integer,allocatable,intent(out) :: iv_array(:)
  
  ii = 3
  allocate(iv_array(3))
  iv_array = 9

  return
end subroutine

 

* visual basic macro

Option Explicit
Option Base 1

Private Declare Sub virtualArrayTest Lib "Dll1.dll" (ByRef iv_array() As Long, ByRef ii As Long)

Sub vattt()
Dim iv_a() As Long
Dim ii As Long

Call virtualArrayTest(iv_a, ii)

Cells(7, 1) = iv_a(1)
Cells(8, 1) = iv_a(2)
Cells(9, 1) = iv_a(3)

End Sub

Excel quit when running. What is the matter?
Thanks very much for any suggestion.

0 Kudos
1 Reply
Steven_L_Intel1
Employee
338 Views

You can't do that. VBA virtual arrays have nothing in common with Fortran arrays. The best I can suggest is to look at SafeArrays - there is a "VB.NET-Safearrays" sample in MixedLanguage.zip in the Fortran Samples folder.

0 Kudos
Reply