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

Fortran Calling VB: How to pass an array?

abhimodak
New Contributor I
779 Views
Hi

I believe this is a very beginer-level question.

{As very neatly shown by the recent post (http://software.intel.com/en-us/forums/showthread.php?t=54555), one can successfully call VB from Fortran. Many thanks to Dmitri/ForAll for that! }

I believe when Fortran calls a VB subroutine with array as an argument, I need to pass a pointer to the array may be along with its length. Then on VB side I will need to "reconstruct" the array. Does that sound right? Is there a sample somewhere? In the Intel Fortran documentation, I could found VB calling Fortran; may be I didn't looked at the correct place.

Specifically, what I am looking for is

Fortran:-
Program Test
Implicit None
Integer :: A(10)
Call Method_In_VB(A)
End Program Test

VB:-
Public Class
Public Sub Method_In_VB(ByRef A)

' Some operations on A

End Sub
End Class



Abhi

0 Kudos
5 Replies
Steven_L_Intel1
Employee
779 Views
There are two samples provided under "Mixed Language" of calling Fortran from VB. Typically, you need to pass A(1) rather than A unless you are going to write Fortran code that deals with SafeArrays (one of the samples does this.)
0 Kudos
abhimodak
New Contributor I
779 Views

Hi Steve

Thanks.

But I am struggling with passing an array "from" Fortran "to" VB. I have created a VB type library and used Fortran Module Wizard to access it on the Fortran side. I believe my interfaces with VB are working fine since I can pass the scalar arguments to VB and launch the required forms etc.

I can create the SafeArrays in Fortran but when I try to pass them to VB these do not work. I am missing something.

Is there some sample code that shows how to do it?

Sincerely

Abhijit

0 Kudos
Steven_L_Intel1
Employee
779 Views

Oh, you're trying to go through the COM interface - that is very different. Unfortunately, it's not a topic I am well versed in. I think the way it works is that you would pass an ordinary Fortran array and the COM interface layer would convert that as needed.

I don't have any samples of doing this. I know that some users here are more versed in COM and may be able to help/

0 Kudos
anthonyrichards
New Contributor III
779 Views
Please define exactly what you mean by 'these do not work'. Show how you are calling the Fortran from VB.
0 Kudos
abhimodak
New Contributor I
779 Views

Hi AnthonyRichards

The attached zip file has 4 fortran files and 1 vb file. I did following:-

(1) The vb file ComTrial.vb is COMclass file created in VB project. This should create a type library named "Test_FortranCallsVB.tlb".

(2) I used the Fortran Module Wizard on this file and generated module file "Test_FortranCallsVB.f90".

(3) The 4 fortran files are included in a Fortran consol project. The module file COMSetup encapsulates initialization of a COM object using program ID while in the module file SafeArray I have made an attempt to create variant array from fortran array.

Currently, when I run the fortran program, the _scalar method works fine. However, nothing happens with the _array method. If I try to pass the variant array, I (correctly) get a type mis-match compile time error.

Sincerely

Abhi

0 Kudos
Reply