Fortran Calling VB: How to pass an array?

Fortran Calling VB: How to pass an array?

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

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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.)

Steve - Intel Developer Support

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

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/

Steve - Intel Developer Support

Please define exactly what you mean by 'these do not work'. Show how you are calling the Fortran from VB.

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

Attachments: 

AttachmentSize
Download CallVB.zip3.23 KB

Leave a Comment

Please sign in to add a comment. Not a member? Join today