- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have a DLL built in IVF10. It returns a vector of double precision values. From VB, I can call the DLL just fine, and if (from VB) I write the vector values to file or display them using msgbox, they look good. However, I cannot use any of the Fortran-generated values in floating point operations in VB (I get a VB error). I tried copying one of the vector elements to a new double precision variable in VB but then cannot use that variable in an equation either.
Does anyone know what the problem could be?
Thanks in advance,
Jeff
I have a DLL built in IVF10. It returns a vector of double precision values. From VB, I can call the DLL just fine, and if (from VB) I write the vector values to file or display them using msgbox, they look good. However, I cannot use any of the Fortran-generated values in floating point operations in VB (I get a VB error). I tried copying one of the vector elements to a new double precision variable in VB but then cannot use that variable in an equation either.
Does anyone know what the problem could be?
Thanks in advance,
Jeff
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - zalcjm
Hi,
I have a DLL built in IVF10. It returns a vector of double precision values. From VB, I can call the DLL just fine, and if (from VB) I write the vector values to file or display them using msgbox, they look good. However, I cannot use any of the Fortran-generated values in floating point operations in VB (I get a VB error). I tried copying one of the vector elements to a new double precision variable in VB but then cannot use that variable in an equation either.
Does anyone know what the problem could be?
Thanks in advance,
Jeff
I have a DLL built in IVF10. It returns a vector of double precision values. From VB, I can call the DLL just fine, and if (from VB) I write the vector values to file or display them using msgbox, they look good. However, I cannot use any of the Fortran-generated values in floating point operations in VB (I get a VB error). I tried copying one of the vector elements to a new double precision variable in VB but then cannot use that variable in an equation either.
Does anyone know what the problem could be?
Thanks in advance,
Jeff
Jeff,
Can you please post the VB code to define the variable and set up the call, and also the Fortran code for the DLL entry point, in particular the !DEC$ ATTRIBUTES lines. The calling conventions used are likely to be the issue.
See my previous post
Regards,
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - David White
Jeff,
Can you please post the VB code to define the variable and set up the call, and also the Fortran code for the DLL entry point, in particular the !DEC$ ATTRIBUTES lines. The calling conventions used are likely to be the issue.
See my previous post
Regards,
David
David,
The skeleton of my code is provided below. On a related note, a co-worker suggested that the Fortran calculations might be tripping a fpe that is not caught with my current compiler settings but which screw things up back in the VB...don't know if that is plausible. Note that if I write the vector to file and read it back in, all is well.
-----------VB------------
Public Declare Sub XYZ5DLL Lib "C:XYZ5DLL.dll" (ByRef DBLOUT As Double)
Dim DBLOUT(0 To 1999) As Double
For i = 0 To 1999
DBLOUT(i) = 0#
Next i
Call XYZ5DLL(DBLOUT(0))
Open "c:junk.dat" For Output As #1
For i = 0 To 1999
Print #1,DBLOUT(i)
Next i
Close #1 ' Fine up to here
For i = 0 To 1999
DBLOUT(i) = 1.0*DBLOUT(i) ' Dies, no matter what type of floating point operation is attempted, even if I copy DBLOUT to new variable
Next i
-------------Fortran----------------
SUBROUTINE XYZ5DLL(DBLOUT)
!DEC$ATTRIBUTES DLLEXPORT :: XYZ5DLL
!DEC$ATTRIBUTES STDCALL,REFERENCE,ALIAS: 'XYZ5DLL' :: XYZ5DLL
DOUBLE PRECISION DBLOUT(2000)
INTEGER I
.
.
{calculations}
.
.
DO I = 1,2000
DBLOUT(I) = 1.0d0*I ! Set some hardcoded values for testing
ENDDO
RETURN
END
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I took the Fortran code you posted and created XYZ5DLL.DLL from it and copied it to the C: disk. The Fortran is attached.
I then added the VB code (together with a few MsgBox lines)to a module in the attached EXCEL file, which calls function GetMyArray in cell B4. The VB code it calls is shown below. It calls the subroutine XYZ5DLL in the DLL and returns the value of DBLOUT(99) to Excel. The value returned is 100, which is as expected. So no problem here.
Public Declare Sub XYZ5DLL Lib "C:XYZ5DLL.dll" (ByRef DBLOUT As Double)
Function GetMyArray() As Integer
Dim DBLOUT(0 To 1999) As Double
MsgBox ("Entered GetMyArray OK")
For i = 0 To 1999
DBLOUT(i) = 0
Next i
Call XYZ5DLL(DBLOUT(0))
MsgBox ("So far, so good OK")
Open "c:junk.dat" For Output As #1
For i = 0 To 1999
Print #1, DBLOUT(i)
Next i
Close #1 ' Fine up to here
For i = 0 To 1999
DBLOUT(i) = 1# * DBLOUT(i) ' Dies, no matter what type of floating point operation is attempted, even if I copy DBLOUT to new variable
Next i
MsgBox ("So far, so good OK")
GetMyArray = DBLOUT(99)
End Function
I then added the VB code (together with a few MsgBox lines)to a module in the attached EXCEL file, which calls function GetMyArray in cell B4. The VB code it calls is shown below. It calls the subroutine XYZ5DLL in the DLL and returns the value of DBLOUT(99) to Excel. The value returned is 100, which is as expected. So no problem here.
Public Declare Sub XYZ5DLL Lib "C:XYZ5DLL.dll" (ByRef DBLOUT As Double)
Function GetMyArray() As Integer
Dim DBLOUT(0 To 1999) As Double
MsgBox ("Entered GetMyArray OK")
For i = 0 To 1999
DBLOUT(i) = 0
Next i
Call XYZ5DLL(DBLOUT(0))
MsgBox ("So far, so good OK")
Open "c:junk.dat" For Output As #1
For i = 0 To 1999
Print #1, DBLOUT(i)
Next i
Close #1 ' Fine up to here
For i = 0 To 1999
DBLOUT(i) = 1# * DBLOUT(i) ' Dies, no matter what type of floating point operation is attempted, even if I copy DBLOUT to new variable
Next i
MsgBox ("So far, so good OK")
GetMyArray = DBLOUT(99)
End Function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - anthonyrichards
I took the Fortran code you posted and created XYZ5DLL.DLL from it and copied it to the C: disk. The Fortran is attached.
I then added the VB code (together with a few MsgBox lines)to a module in the attached EXCEL file, which calls function GetMyArray in cell B4. The VB code it calls is shown below. It calls the subroutine XYZ5DLL in the DLL and returns the value of DBLOUT(99) to Excel. The value returned is 100, which is as expected. So no problem here.
Public Declare Sub XYZ5DLL Lib "C:XYZ5DLL.dll" (ByRef DBLOUT As Double)
Function GetMyArray() As Integer
Dim DBLOUT(0 To 1999) As Double
MsgBox ("Entered GetMyArray OK")
For i = 0 To 1999
DBLOUT(i) = 0
Next i
Call XYZ5DLL(DBLOUT(0))
MsgBox ("So far, so good OK")
Open "c:junk.dat" For Output As #1
For i = 0 To 1999
Print #1, DBLOUT(i)
Next i
Close #1 ' Fine up to here
For i = 0 To 1999
DBLOUT(i) = 1# * DBLOUT(i) ' Dies, no matter what type of floating point operation is attempted, even if I copy DBLOUT to new variable
Next i
MsgBox ("So far, so good OK")
GetMyArray = DBLOUT(99)
End Function
I then added the VB code (together with a few MsgBox lines)to a module in the attached EXCEL file, which calls function GetMyArray in cell B4. The VB code it calls is shown below. It calls the subroutine XYZ5DLL in the DLL and returns the value of DBLOUT(99) to Excel. The value returned is 100, which is as expected. So no problem here.
Public Declare Sub XYZ5DLL Lib "C:XYZ5DLL.dll" (ByRef DBLOUT As Double)
Function GetMyArray() As Integer
Dim DBLOUT(0 To 1999) As Double
MsgBox ("Entered GetMyArray OK")
For i = 0 To 1999
DBLOUT(i) = 0
Next i
Call XYZ5DLL(DBLOUT(0))
MsgBox ("So far, so good OK")
Open "c:junk.dat" For Output As #1
For i = 0 To 1999
Print #1, DBLOUT(i)
Next i
Close #1 ' Fine up to here
For i = 0 To 1999
DBLOUT(i) = 1# * DBLOUT(i) ' Dies, no matter what type of floating point operation is attempted, even if I copy DBLOUT to new variable
Next i
MsgBox ("So far, so good OK")
GetMyArray = DBLOUT(99)
End Function
Hi,
It looks like your Fortran is the same as my original code. I am actually calling from VB6, not VBA. The VB6 code is a DLL that is a user extension in a chemical process flowsheeting software. So far, the only thing that works is writing the vector to a scratch file then reading it back in...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I suggest running your code in debug mode and looking at what you are getting. I believe VB uses STDCALL convention by default, so I do not see what the problem can be.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page