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

Trying to pass 2 or more (1 dimension) array from FORTRAN to VBA (X64)

Aburelo
Novice
483 Views

Hello , i was trying to pass 2 arrays from fortran to vba ,i get passing 1 or 2  arrays , but when i try to pass 3 or more , Excel Crashes .

 

 

FOR 1 ARRAY 1 Dimension i didnt have problems 

this is the code:

 

:::::::::::::::::::::::::::::::::::::::::::::::::::::: 1 ARRAY 1 DIMENSION ::::::::::::::::::::::::::::::::::::::::::::::::::::::::

FORTRAN SIDE:

 

      SUBROUTINE INOUTA (FIV)
	!DEC$ ATTRIBUTES DLLEXPORT,stdcall,reference,ALIAS:'INOUTA' :: INOUTA
      Real, Dimension(20,1) :: FIV
      
      DO 1 I=1,20
      FIV(I,1)=I*2
   1  CONTINUE 
      RETURN
      END

 

 

VBA SIDE:

 

Public Declare PtrSafe Sub ABSUB Lib "ABSINOUT.dll" Alias "INOUTA" (outarray As Single)

Public Function FABS() As Variant

ABSactualWorkpath = ThisWorkbook.Path
ChDir ABSactualWorkpath

Dim ALEX(1 To 20, 1 To 1) As Single
Call ABSUB(ALEX(1, 1))

FABS = ALEX
End Function

 

 

:::::::::::::::::::::::::::::::::::::::::::: 2 ARRAYS 1 DIMENSION ::::::::::::::::::::::::::::::::::::::::::::::::::::

Fortran side:

 

      SUBROUTINE INOUTA (FIV,POX)
	!DEC$ ATTRIBUTES DLLEXPORT,reference,stdcall,ALIAS:'INOUTA' :: INOUTA
      Real, Dimension(20,1),intent(INOUT) :: FIV,POX
      
      DO 1 I=1,20
      FIV(I,1)=I*1
   1  CONTINUE 
      
      DO 2 I=1,20
      POX(I,1)=I*2
   2  CONTINUE 
      RETURN
      END SUBROUTINE INOUTA

 

vba side:

 

Public Declare PtrSafe Sub ABSUB Lib "ABSINOUT.dll" Alias "INOUTA" (ByRef outarray As Single, ByRef outarry As Single)

Public Function FABS() As Variant

ABSactualWorkpath = ThisWorkbook.Path
ChDir ABSactualWorkpath

Dim ALEX(1 To 20, 1 To 1) As Single
Dim ALEXX(1 To 20, 1 To 1) As Single

Call ABSUB(ALEX(1, 1), ALEXX(1, 1))

FABS = ALEX
End Function

 

 

but whwn i try to pass 3 arrays excel crashes:

this is the code i wrote for 3 arrays

::::::::::::::::::::::::::::::::::::::::::::: 3 ARRAYS 1 DIMENSION ::::::::::::::::::::::::::::::::::::::::::::::::::::

 

Fortran:

 

      SUBROUTINE INOUTA (FIV,POX,TETP)
	!DEC$ ATTRIBUTES DLLEXPORT,reference,stdcall,ALIAS:'INOUTA' :: INOUTA
      Real, Dimension(20,1),intent(INOUT) :: FIV,POX,TETP
      
      DO 1 I=1,20
      FIV(I,1)=I*1
   1  CONTINUE 
      
      DO 2 I=1,20
      POX(I,1)=I*2
   2  CONTINUE 
      
      DO 3 I=1,20
      TETP(I,1)=I*3
   3  CONTINUE
      
      RETURN
      END SUBROUTINE INOUTA

 

 

VBA SIDE:

 

Public Declare PtrSafe Sub ABSUB Lib "ABSINOUT.dll" Alias "INOUTA" (ByRef outarray As Single, ByRef outarry As Single, ByRef outay As Single)

Public Function FABS() As Variant

ABSactualWorkpath = ThisWorkbook.Path
ChDir ABSactualWorkpath

Dim ALEX(1 To 20, 1 To 1) As Single
Dim ALEXX(1 To 20, 1 To 1) As Single
Dim ALEXXX(1 To 20, 1 To 1) As Single

Call ABSUB(ALEX(1, 1), ALEXX(1, 1), ALEXXX(1, 1))

FABS = ALEX
End Function

 

 

did you know why is this happening?  i annex both examples , you need to use 64 bits excel to run it.

 

 

 

0 Kudos
1 Solution
Aburelo
Novice
446 Views

UPDATE#6 ... i find no matters if you activate  the references , just activate one of them , and this repair the file.... i dont know why but i think its only refreshing the references

View solution in original post

0 Kudos
7 Replies
Aburelo
Novice
469 Views

UPDATE1: I open my file in another computer, and i was able to get 2 arrays, , i think the problem is related to the excel version or computer settings...

 

UPDATE2:  i update my EXCEL 365 to the version 2207 Build 16.0.15427.20182 64-bits  and it helps for the  2 arrays error but i still not able to run 3 or more....:/

0 Kudos
Aburelo
Novice
456 Views

UPDATE#3: I ADDED THIS REFERENCES IN VBA EXCEL REFERENCES TABLE...suprisely the code now work for 3 arrays!, going to try for 5 arrays to see if that helps!

 

 

Aburelo_0-1661254042064.png

 

 

 

I ANNEX THE REFERENCES CODES  (i added these files in this reply), added to your reference code in visual basic in excel and select the VFPROj.dll and acept it magically it start working!  , Also i copy the file to my another computer and works too =,D!

Aburelo_0-1661254869210.png

 

 

0 Kudos
Aburelo
Novice
453 Views

UPDATE #4  , trying to pass 4 arrays breaks excels again......the solution was dissabling the "Intel Fortran project Extensibility 13.0 type library" and then its start working for 4 arrays......

 

Aburelo_2-1661256027250.png

 

 

also i activate the Intel Fortran project Extensibility 18.0 type library and excel keep working well...

 

 

0 Kudos
Aburelo
Novice
448 Views

UPDATE#5  I try with 6 arrays and stop working... i desactivate the  Intel Fortran project Extensibility 18.0 type library and then ...solved...weird but now it can hanndle 6 arrays without problem

0 Kudos
Aburelo
Novice
447 Views

UPDATE#6 ... i find no matters if you activate  the references , just activate one of them , and this repair the file.... i dont know why but i think its only refreshing the references

0 Kudos
AlHill
Super User
437 Views

Let us know when you get to 128 arrays.

 

Doc (not an Intel employee or contractor)
[Maybe Windows 12 will be better]

0 Kudos
Aburelo
Novice
424 Views

Sorry i was trying to be detailed because this cost me lot of time , i hope someday one person have the same problem and this post help him. I notice for 3 or more arrays you need to able that reference, but after that you need to Refresh your refereces. that only that.

Reply