<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Passing Arrays from MS Excel to a DLL in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Passing-Arrays-from-MS-Excel-to-a-DLL/m-p/931582#M14936</link>
    <description>Hi &lt;BR /&gt; &lt;BR /&gt;(1) &lt;BR /&gt;I was delighted to (eventually) be able to access a FORTRAN 6.1 DLL from MS &lt;BR /&gt;Excel. The example DLL I made and used had only discrete numerical inputs &lt;BR /&gt;and these were supplied by simply selecting the appropriate spreadsheet &lt;BR /&gt;cells after typing the function name, adding the commas, etc. So far, so &lt;BR /&gt;good. &lt;BR /&gt; &lt;BR /&gt;My next attempt involved arguments that consisted of arrays of numbers. The &lt;BR /&gt;problem comes with the need to supply FORTRAN only the first element of an &lt;BR /&gt;array (or, the address?). How can I supply only the first element when &lt;BR /&gt;selecting a range of cells in the spreadsheet? Also, what is the correct way &lt;BR /&gt;to declare a function in VBA so that it recognizes that a particular &lt;BR /&gt;argument is an array? &lt;BR /&gt; &lt;BR /&gt;The FORTRAN function looks like : &lt;BR /&gt; &lt;BR /&gt;Function LINEARLOOKUP(X,XARRAY,YARRAY,NUMENTRIES) &lt;BR /&gt; &lt;BR /&gt;and my VBA declaration : &lt;BR /&gt; &lt;BR /&gt;Declare Function LINEARLOOKUP Lib "LibName.DLL" Alias "_LINEARLOOKUP*16" &lt;BR /&gt;(Byval X as Single,ByVal XARRAY() as single,byVal YARRAY() as &lt;BR /&gt;single,NUMENTRIES as long) as single &lt;BR /&gt; &lt;BR /&gt;The result, when attempting to supply the array arguments as a selection of &lt;BR /&gt;cells is #VALUE! I'm stumped and terribly frustrated. Please help if you &lt;BR /&gt;can. &lt;BR /&gt; &lt;BR /&gt;(2) I am u user in the JSF program at Boeing and as such I do not have &lt;BR /&gt;access to the installation disks; is there some way I can become a recipient &lt;BR /&gt;of the VF Newsletter? &lt;BR /&gt; &lt;BR /&gt;Thanks in anticipation &lt;BR /&gt; &lt;BR /&gt;Colin Widdison</description>
    <pubDate>Thu, 14 Dec 2000 08:22:10 GMT</pubDate>
    <dc:creator>Intel_C_Intel</dc:creator>
    <dc:date>2000-12-14T08:22:10Z</dc:date>
    <item>
      <title>Passing Arrays from MS Excel to a DLL</title>
      <link>https://community.intel.com/t5/Software-Archive/Passing-Arrays-from-MS-Excel-to-a-DLL/m-p/931582#M14936</link>
      <description>Hi &lt;BR /&gt; &lt;BR /&gt;(1) &lt;BR /&gt;I was delighted to (eventually) be able to access a FORTRAN 6.1 DLL from MS &lt;BR /&gt;Excel. The example DLL I made and used had only discrete numerical inputs &lt;BR /&gt;and these were supplied by simply selecting the appropriate spreadsheet &lt;BR /&gt;cells after typing the function name, adding the commas, etc. So far, so &lt;BR /&gt;good. &lt;BR /&gt; &lt;BR /&gt;My next attempt involved arguments that consisted of arrays of numbers. The &lt;BR /&gt;problem comes with the need to supply FORTRAN only the first element of an &lt;BR /&gt;array (or, the address?). How can I supply only the first element when &lt;BR /&gt;selecting a range of cells in the spreadsheet? Also, what is the correct way &lt;BR /&gt;to declare a function in VBA so that it recognizes that a particular &lt;BR /&gt;argument is an array? &lt;BR /&gt; &lt;BR /&gt;The FORTRAN function looks like : &lt;BR /&gt; &lt;BR /&gt;Function LINEARLOOKUP(X,XARRAY,YARRAY,NUMENTRIES) &lt;BR /&gt; &lt;BR /&gt;and my VBA declaration : &lt;BR /&gt; &lt;BR /&gt;Declare Function LINEARLOOKUP Lib "LibName.DLL" Alias "_LINEARLOOKUP*16" &lt;BR /&gt;(Byval X as Single,ByVal XARRAY() as single,byVal YARRAY() as &lt;BR /&gt;single,NUMENTRIES as long) as single &lt;BR /&gt; &lt;BR /&gt;The result, when attempting to supply the array arguments as a selection of &lt;BR /&gt;cells is #VALUE! I'm stumped and terribly frustrated. Please help if you &lt;BR /&gt;can. &lt;BR /&gt; &lt;BR /&gt;(2) I am u user in the JSF program at Boeing and as such I do not have &lt;BR /&gt;access to the installation disks; is there some way I can become a recipient &lt;BR /&gt;of the VF Newsletter? &lt;BR /&gt; &lt;BR /&gt;Thanks in anticipation &lt;BR /&gt; &lt;BR /&gt;Colin Widdison</description>
      <pubDate>Thu, 14 Dec 2000 08:22:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Passing-Arrays-from-MS-Excel-to-a-DLL/m-p/931582#M14936</guid>
      <dc:creator>Intel_C_Intel</dc:creator>
      <dc:date>2000-12-14T08:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Arrays from MS Excel to a DLL</title>
      <link>https://community.intel.com/t5/Software-Archive/Passing-Arrays-from-MS-Excel-to-a-DLL/m-p/931583#M14937</link>
      <description>(1)  You don't really show enough info about LINEARLOOKUP to be definitive about your code, although I'll make some general statements.   &lt;BR /&gt;It's unlikely that you want byVal for any of the parameters in the VB/VBA Declare statement.  Also, don't use "XARRAY() as single" for the array, instead use "XARRAY as Single".  The former is a topic for a more advanced discussion.  The latter is what you want to pass the first element of the array in that position. &lt;BR /&gt; &lt;BR /&gt;Here's a simple example for you: &lt;BR /&gt;&lt;PRE&gt;&lt;FONT size="+0"&gt; 
! f90 
subroutine Severity(lambda, pmean, pstd, numsims, sims) 
  implicit none 
  !DEC$ ATTRIBUTES DLLEXPORT :: Severity 
 
  ! dummy arguments 
  real, intent(IN) :: lambda, pmean, pstd 
  integer, intent(IN) :: numsims 
  real, dimension(1:numsims), intent(OUT) :: sims 
 
  ! ... 
end subroutine Severity 
 
------------- 
' Excel VBA code for Sheet1 
Private Declare Sub _SEVERITY@20 Lib "Psnd.dll" Alias "Severity" (lambda As _ 
Single, pmean As Single, pstd As Single, numsims As Long, sims As Single) 
 
Sub sims2() 
    Dim mysim() As Single, i As Long, TargetRange As Range 
    ReDim mysim(1 To [Simulations], 1 To 1) 
     
    Call Severity([lambda], [Mean], [StDev], [Simulations], mysim(1, 1)) 
    Set TargetRange = Range(Range("TopLeft").Offset(0, 5), Range("TopLeft").Offset([Simulations] - 1, 5)) 
    TargetRange.Value = mysim 
' ... 
End Sub 
&lt;/FONT&gt;&lt;/PRE&gt; &lt;BR /&gt;note: &lt;BR /&gt;lambda, Mean, StDev, Simulations are range names (the brackets - [] - are the evaluate operator).  XL columns map to vectors as N x 1 arrays.  This passes the array mysim to the f90 code by passing mysim(1, 1) by reference, the address of the start of the array is passed to the f90 code - which is what it expects in this case. &lt;BR /&gt; &lt;BR /&gt;(2) If you didn't know already, you can catch up all but the most recent newsletters at &lt;A href="http://www.compaq.com/fortran/visual/newsletter.html" target="_blank"&gt;http://www6.compaq.com/fortran/visual/newsletter.html&lt;/A&gt;. &lt;BR /&gt; &lt;BR /&gt;hth, &lt;BR /&gt;John</description>
      <pubDate>Thu, 14 Dec 2000 16:41:34 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Passing-Arrays-from-MS-Excel-to-a-DLL/m-p/931583#M14937</guid>
      <dc:creator>Intel_C_Intel</dc:creator>
      <dc:date>2000-12-14T16:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Arrays from MS Excel to a DLL</title>
      <link>https://community.intel.com/t5/Software-Archive/Passing-Arrays-from-MS-Excel-to-a-DLL/m-p/931584#M14938</link>
      <description>Here is how someone did what you want. The following text was saved from &lt;BR /&gt;a thread in the previous message board. &lt;BR /&gt; &lt;BR /&gt;QUOTE" &lt;BR /&gt;  &lt;BR /&gt;When VBA code passes the first element of an array to a Fortran DLL, &lt;BR /&gt;then the address of that array element is passed,  &lt;BR /&gt;which is what Fortran expects to receive.  &lt;BR /&gt; &lt;BR /&gt;Using named ranges in Excel makes pasting in an array of &lt;BR /&gt;values returned by Fortran relatively easy. My practice is to use &lt;BR /&gt;the same names for the named ranges in my worksheet and the corresponding &lt;BR /&gt;arrays in my VBA code. You can then use VBA code something like this:  &lt;BR /&gt; &lt;BR /&gt;Option Explicit  &lt;BR /&gt;Option Base 1  &lt;BR /&gt;'  &lt;BR /&gt;' Declare VLE_CALC as DLLEXPORTed subroutine in  &lt;BR /&gt;' Fortran DLL file core_routine.dll. Arrays  &lt;BR /&gt;' componentMass and bublMassGas are double precision  &lt;BR /&gt;' arrays passed explicitly by reference.  &lt;BR /&gt;'  &lt;BR /&gt;Private Declare Sub VLE_CALC Lib "core_routine.dll" _(ByRef componentMass As Double, _  &lt;BR /&gt;ByRef bublMassGas As Double)  &lt;BR /&gt; &lt;BR /&gt;Sub calcVLEBtn_Click()  &lt;BR /&gt;'  &lt;BR /&gt;' Declare the componentMass and bublMassGas arrays as  &lt;BR /&gt;' both being componentArraySize in length. Variant  &lt;BR /&gt;' array componentMassVnt corresponds to double  &lt;BR /&gt;' precision array componentMass.  &lt;BR /&gt;'  &lt;BR /&gt;Const componentArraySize As Long = 50  &lt;BR /&gt;Dim counter As Long  &lt;BR /&gt;Dim componentMass(componentArraySize) As Double  &lt;BR /&gt;Dim componentMassVnt As Variant  &lt;BR /&gt;Dim bublMassGas(componentArraySize, 1) As Double  &lt;BR /&gt;'  &lt;BR /&gt;' Select the worksheet on which the named range  &lt;BR /&gt;' componentMass exists. Read the range into the  &lt;BR /&gt;' variant array componentMassVnt in a single  &lt;BR /&gt;' statement. The same thing could be done in a For  &lt;BR /&gt;' loop.  &lt;BR /&gt;'  &lt;BR /&gt;Worksheets("VLE_calc").Select  &lt;BR /&gt;componentMassVnt = Range("componentMass").Value  &lt;BR /&gt;'  &lt;BR /&gt;' The For loop copies the values from the variant  &lt;BR /&gt;' array componentMassVnt into the double precision  &lt;BR /&gt;' array componentMass. It also initializes the  &lt;BR /&gt;' bublMassGass array.  &lt;BR /&gt;'  &lt;BR /&gt;For counter = 1 To componentArraySize Step 1  &lt;BR /&gt;componentMass(counter) = CDbl(componentMassVnt(counter, 1))  &lt;BR /&gt;bublMassGas(counter, 1) = CDbl(0)  &lt;BR /&gt;Next counter  &lt;BR /&gt;'  &lt;BR /&gt;' Call the VLE_CALC subroutine in the Fortran DLL  &lt;BR /&gt;' passing the componentMass array as input and the  &lt;BR /&gt;' bublMassGas array as output.  &lt;BR /&gt;'  &lt;BR /&gt;Call VLE_CALC(componentMass(1), bublMassGas(1, 1))  &lt;BR /&gt;'  &lt;BR /&gt;' Copy the values in the bublMassGas array into the  &lt;BR /&gt;' named range bublMassGas in the worksheet. You can  &lt;BR /&gt;' also use a For loop to do the same thing.  &lt;BR /&gt;'  &lt;BR /&gt;Range("bublMassGas").Value = bublMassGas  &lt;BR /&gt;'  &lt;BR /&gt;End Sub  &lt;BR /&gt; &lt;BR /&gt;"UNQUOTE &lt;BR /&gt; &lt;BR /&gt;HTH &lt;BR /&gt; &lt;BR /&gt;Tony Richards</description>
      <pubDate>Thu, 14 Dec 2000 20:52:04 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Passing-Arrays-from-MS-Excel-to-a-DLL/m-p/931584#M14938</guid>
      <dc:creator>Intel_C_Intel</dc:creator>
      <dc:date>2000-12-14T20:52:04Z</dc:date>
    </item>
  </channel>
</rss>

