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

Just a little problem interfacing VB and Fortran

charlesdayan
Beginner
281 Views
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 ?
0 Kudos
2 Replies
durisinm
Novice
281 Views
Why are you using !MS$ATTRIBUTES instead of !DEC$ATTRIBUTES? What version of Fortran are you using?
Using the debuggers on the VB and Fortran sides, can you verify the contents of the integer array before the call from VB and after your Fortran subroutine begins execution?
Mike D.
0 Kudos
rahzan
Novice
281 Views
I think all you need to do is to chg your line:
Integer(4) , intent(inout) :: xx
to:
Integer(4) , intent(inout) :: xx(mm,nn)
+you might need to put the declarations for mm & nn before it.
I can't tell why it works with real(8) and not with int(4).
Also, your loop is row-major, it is much slower than col.major suitable for both VB and f90.
Finally, if you're still on cvf it is best to use com-servers instead of "naked" dlls.

Message Edited by Rahzan on 03-03-2005 01:09 PM

0 Kudos
Reply