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

Calling Fortran DLL from Excel.

Intel_C_Intel
Employee
1,550 Views

I have attempted to call a Fortran DLL from Excel with no success. The code converts either (1) a Latitude Longitude location to Section, Township, Range or (2) vice versa.Thefortran source codemay be found here:

http://www.geocities.com/jeremiahobrien/download.html

Can someone assist me?

Thanks,

Jim

Option Explicit

Private Sub CommandButton1_Click()
trsm = InputBox("Enter Section/Township/Range")
meridian = InputBox("OPTIONAL/enter meridian")
state = InputBox("OPTIONAL/enter state XX")
Call trsm2ll(trsm, Len(trsm), meridian, Len(meridian), state, Len(state), lat, lng, lerror)
MsgBox "latitude=" & lat & " longitude=" & lng & " error=" & lerror & " trsm=" & trsm & " state=" & state & " meridian=" & meridian
End Sub

Private Sub CommandButton2_Click()
lat = InputBox("enter Latitude xx.xxx")
lng = InputBox("enter Longitude xxx.xxx")
state = InputBox("OPTIONAL/enter state XX")
Call ll2trsm(lat, lng, trsm, Len(trsm), meridian, Len(meridian), state, Len(state))
MsgBox "TRS=" & trsm & " Meridian=" & meridian & " state=" & state
End Sub

Option Explicit

Public lerror As Integer
Public lat As Single
Public lng As Single
Public state As String * 2
Public meridian As String * 2
Public trsm As String * 16
Declare Sub trsm2ll Lib _
"TRSM2LL.DLL" _
(ByVal trsm As String, ByVal l1 As Long, _
ByVal meridian As String, ByVal l2 As Long, _
ByVal state As String, ByVal l3 As Long, _
lat As Single, _
lng As Single, _
lerror As Integer)

Declare Sub ll2trsm Lib _
"LL2TRSM.DLL" _
(lat As Single, _
lng As Single, _
ByVal trsm As String, ByVal l1 As Long, _
ByVal meridian As String, ByVal l2 As Long, _
ByVal state As String, ByVal l3 As Long)

0 Kudos
6 Replies
anthonyrichards
New Contributor III
1,550 Views

Do a forum search for 'Fortran DLL EXCEL' and you will find loads of advice. You could start here http://software.intel.com/en-us/forums/showpost.php?p=3886

If you are sending strings, I would make them 'by ref' and put them at the end. They would need to be given the REFERENCE attribute in the Fortran.

Where is your Fortran code by the way?

0 Kudos
Steven_L_Intel1
Employee
1,550 Views
ByVal for strings is correct. On the Fortran side, you need to give the character argument the REFERENCE attribute so that it will not look for a length.
0 Kudos
Intel_C_Intel
Employee
1,550 Views

The Fortran DLL is in the c: oot directory. I have not re-compiled under the Intel Fortran Compiler yet but downloaded the DLL's from the referenced web site in my post.

Thanks,

Jim

0 Kudos
Steven_L_Intel1
Employee
1,550 Views

Ok, so this is not related to Intel Fortran at all? You have a DLL someone else built and are trying to use it from Excel. What exactly is the problem you encounter?

I find that I have to put the full path to the DLL in the VBscript code unless perhaps the DLL is located where the Excel application itself is located. C:ROOT is not generally a meanintgful directory in Windows.

If you need more help, perhaps you can ask the DLL author who promises to respond to emails.

0 Kudos
anthonyrichards
New Contributor III
1,550 Views
When I clicked on thelink to the Fortran, my IE Content Advisor cut in and warned me about the site, so I would stay clear of it...
0 Kudos
Steven_L_Intel1
Employee
1,550 Views
The site seemed ok to me. I use Firefox. A rather simple site.
0 Kudos
Reply