Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Little problem interfacing VB and Fortran

Status
Not open for further replies.

CharlesDayan

Technical User
Feb 26, 2005
4
BR
I'm trying to send two arrays (a double and a long) from VB to a FORTRAN DLL. I don't understand why I can get (without problems) all variables but my array of longs? The DLL returns the same array; it accepts the call but doesn't perform any calculation with the array!!???

Here the short code:

Subroutine VB_FOR(x,n,m,r,xx,nn,mm,rr)
implicit none
!
!MS$ATTRIBUTES DLLEXPORT :: VB_FOR
!MS$ATTRIBUTES ALIAS : 'VB_FOR' :: VB_FOR
!
Real(8) , intent(inout) :: x
Integer(2) , intent(in) :: n
Integer(2) , intent(in) :: m
Real(8) , intent(inout) :: r

Integer(4) , intent(inout) :: xx
Integer(2) , intent(in) :: nn
Integer(2) , intent(in) :: mm
Integer(4) , intent(inout) :: rr

dimension x(n,m) ! dimension of the array of doubles
dimension xx(nn,mm) ! ... array of longs

integer :: i
integer :: j

do i=1,n
do j=1,m
x(i,j)=x(i,j)*n/10 ! WORKS FINE
end do
end do

r=2.13*r*r ! WORKS FINE

do i=1,nn
do j=1,mm
xx(i,j)=xx(i,j)*xx(i,j) ! DO NOT WORK (?)
end do
end do

rr=rr*rr ! WORKS FINE

end subroutine

The Visual Basic 6 side:

Private Declare Sub VB_FOR Lib "VB_FOR.dll" (ByRef Array_Dbl As Double, ByRef Linha_Dbl As Integer, ByRef Coluna_Dbl As Integer, ByRef Duplo_Dbl As Double, ByRef Array_Lng As Long, ByRef Linha_Lng As Integer, ByRef Coluna_Lng As Integer, ByRef Longo_Lng As Long)

Sub CallDLL_Click()
.
.
.
Call VB_FOR(MyDblArr(1, 1), n, m, My_Double, MyLngArr(1, 1), nn, mn, My_Long)
.
.
.
End Sub


ANY SUGGESTION ?
 
What is the difference in size between Integer and Long in VB?
 
Do you mean: Integer[vb] <=> Integer(2)[fortran]
Long[vb] <=> Integer(4)[fortran]
 
No - you are perfectly right: VB Integer = INTEGER*2 and VB Long = INTEGER*4.

Why not try a 1 dimensional array first - see if that works with longs?

I'm just guessing here as I don't have an MS environment.
 
It is incredible, your hint worked! The program works for 1 dimensional arrays (vectors)! But the mystery continues :( !
 
Try a 1D array in VB and access it as a 2D array in Fortran. Also try a 2D array in VB and access it as a 1D array in Fortran.

If the latter works, then you may have to do some computation on the indices (xx(a,b) (VB) = xx((a - 1) * bmax + b) (Fortran).

At a guess, it is something to do with the implementation of 2D arrays - they are probably not the same in both languages. Can't think of anything else.
 
1- Nop! I can't access send the arrays with different dimensions!

2- The array definitions between VB (not VBNet) and Fortran are the same! If I declare explicitly (i.e. dimension xx(11,33) ! ... array of longs) the program works.

Let me put my problem again: I want to pass a array from VB to fortran, but the fortran dll has no previous knowledge about the array dimension.

ANY SUGGESTIONS ABOUT THE USE OF POINTERS WILL BE APPRECIATE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top