<?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>sujet Re: Help with passing VBA string to Fortran dans Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Help-with-passing-VBA-string-to-Fortran/m-p/1375354#M160922</link>
    <description>&lt;P&gt;Thanks FortranFan, that gave me exactly what I was after!&lt;/P&gt;</description>
    <pubDate>Thu, 07 Apr 2022 21:50:14 GMT</pubDate>
    <dc:creator>ripittard</dc:creator>
    <dc:date>2022-04-07T21:50:14Z</dc:date>
    <item>
      <title>Help with passing VBA string to Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Help-with-passing-VBA-string-to-Fortran/m-p/1374987#M160906</link>
      <description>&lt;P&gt;I am trying to pass a VBA string to fortran, modify it and return the result and am having some trouble.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought I could have VBA pass the size of the string and a reference to the string to Fortran and then use&amp;nbsp;ConvertBSTRToString to obtain the Fortran equivalent, but I am struggling to do this correctly.&lt;/P&gt;
&lt;P&gt;The lenght of the string comes across OK, but&amp;nbsp;ConvertBSTRToString&amp;nbsp; result does not match and the string content in Fortran does not match.&amp;nbsp; Any help woudl be appreciated.&lt;/P&gt;
&lt;P&gt;The Fortran routine and VBA code are attached.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 23:10:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Help-with-passing-VBA-string-to-Fortran/m-p/1374987#M160906</guid>
      <dc:creator>ripittard</dc:creator>
      <dc:date>2022-04-06T23:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Help with passing VBA string to Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Help-with-passing-VBA-string-to-Fortran/m-p/1375029#M160909</link>
      <description>&lt;P&gt;&lt;a href="https://community.intel.com/t5/user/viewprofilepage/user-id/204097"&gt;@ripittard&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;This post may be of limited value to you since what is below is prescriptive.&amp;nbsp; But if interested, take a look at this thread which has Fortran with VB.NET (a different beast of course) :&amp;nbsp;&lt;A href="https://community.intel.com/t5/Intel-Fortran-Compiler/x64-string-passing/td-p/1373313" target="_blank" rel="noopener"&gt;https://community.intel.com/t5/Intel-Fortran-Compiler/x64-string-passing/td-p/1373313&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;But you can consume the same Fortran subroutine shown in it in Microsoft Office VBA as follows: the key aspects are ByVal attribute for the string parameter and (preferably) LongPtr type to match with preferably c_size_t kind for the integer on the Fortran side, this one too as ByVal:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;Option Explicit
Public Declare PtrSafe Sub Fstr Lib "c:\temp\Fdll.dll" (ByVal Str As String, ByVal LenStr As LongPtr)
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And a trivial button example below to see how the subroutine can be invoked in Excel:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;Private Sub cmdBtn_Click()

   Dim LenStr As LongPtr
   Dim Str As String

   On Error GoTo StrErr

   Range("Str").Clear
   LenStr = Range("LenStr").Value
   If (LenStr &amp;gt; 0) Then
      Str = String(CLng(LenStr), " ")
      Call Fstr(Str, LenStr)
      Range("Str").Value = Str
   Else
      Range("Str").Value = xlErrNA
   End If
   Exit Sub
    
StrErr:
   Range("Str").Value = xlErrNA
    
End Sub
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 03:02:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Help-with-passing-VBA-string-to-Fortran/m-p/1375029#M160909</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2022-04-07T03:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: Help with passing VBA string to Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Help-with-passing-VBA-string-to-Fortran/m-p/1375354#M160922</link>
      <description>&lt;P&gt;Thanks FortranFan, that gave me exactly what I was after!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 21:50:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Help-with-passing-VBA-string-to-Fortran/m-p/1375354#M160922</guid>
      <dc:creator>ripittard</dc:creator>
      <dc:date>2022-04-07T21:50:14Z</dc:date>
    </item>
  </channel>
</rss>

