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

Passing array of doubles from VB to IVF dll

zalcjm
Beginner
264 Views
Hi,

I have a simple VB code that loads an IVF dll. If I call the Fortran routine in that dll from VB without passing any data, it works fine. If I pass an array of doubles (but don't do anything with them on the Fortran side), everything works fine so long as the length of the double array is less than ~100. If the array length is greater than 100, the Fortran seems to execute just fine but everything crashes upon return to VB. This is very reproducible. Is there a workaround or should I pass multiple vectors, each of relatively short length?

TIA,
Jeff
0 Kudos
2 Replies
anthonyrichards
New Contributor III
264 Views
Quoting - zalcjm
Hi,

I have a simple VB code that loads an IVF dll. If I call the Fortran routine in that dll from VB without passing any data, it works fine. If I pass an array of doubles (but don't do anything with them on the Fortran side), everything works fine so long as the length of the double array is less than ~100. If the array length is greater than 100, the Fortran seems to execute just fine but everything crashes upon return to VB. This is very reproducible. Is there a workaround or should I pass multiple vectors, each of relatively short length?

TIA,
Jeff

This is frequently posted problem. If you do a forum search using 'Visual Basic' you should find some useful help.
A summary of the precautions you should take first is as follows:

on VB side
1. Declare numerical variables as usual as either scalars or arrays as required; these are passed ByRef
2. Declare string variables as usual (possibly pad with blanks to required length); these are passed ByVal

on Fortran side
1. Declare dummy arguments (including scalar real arguments) as arrays of dimension (1) or actual dimension if larger
2. Use !DEC$ ATTRIBUTES REFERENCE :: for string arguments only

0 Kudos
DavidWhite
Valued Contributor II
264 Views
Quoting - anthonyrichards

This is frequently posted problem. If you do a forum search using 'Visual Basic' you should find some useful help.
A summary of the precautions you should take first is as follows:

on VB side
1. Declare numerical variables as usual as either scalars or arrays as required; these are passed ByRef
2. Declare string variables as usual (possibly pad with blanks to required length); these are passed ByVal

on Fortran side
1. Declare dummy arguments (including scalar real arguments) as arrays of dimension (1) or actual dimension if larger
2. Use !DEC$ ATTRIBUTES REFERENCE :: for string arguments only


If the passing is the same as from VBA, in the caller, define the arrays as needed, but use actual arguments like ARRAY1(1), ARRAY2(1), etc.

On the Fortran side, you need to use e,e
!DEC$ ATTRIBUTES REFERENCE :: RealIn,NRealIn,NIntIn,IntIn,NRealOut,RealOut,NCharOut,Str
For ALL arguments (not just strings)

As you can see, I have passed the array sizes as well, so these are declared like
Real(KIND=8), INtent(IN) :: RealIn(NRealIn)

Hope this helps.


David
0 Kudos
Reply