title: Using Fortran DLL in VB
body: <p>I am trying to teach myself calling fortran subroutine from VB. And I am trying to work with really simple examples, but somehow it is not working. I am using Visual Studio 2010, with Intel Visual Fortran. Here is the code I am trying:</p>
  
  <pre><code>SUBROUTINE ARRAYTEST(arr)
  !DEC$ ATTRIBUTES DLLEXPORT, ALIAS:"ARRAYTEST" :: ARRAYTEST
  REAL arr(3, 7)
  INTEGER i, j
  DO i = 1, 3
      DO j = 1, 7
          arr (i, j) = 11.0 * i + j
      END DO
  END DO
  END SUBROUTINE
  </code></pre>
  
  <p>And it builds successfully to create a DLL file. And Here is my Visual basic code:</p>
  
  <pre><code>Public Class Form1
  Private Declare Sub ARRAYTEST Lib "FortTest.DLL" Alias "ARRAYTEST" (ByVal x As Single)
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim arr(0 To 2, 0 To 6) As Single
      Call ARRAYTEST(arr(0, 0))
      TextBox1.Text = arr(3, 3)
  End Sub
  
  End Class
  </code></pre>
  
  <p>　When I put the DLL file into the directory, and run the code, I got the following error:
  A first chance exception of type 'System.AccessViolationException' occurred in ForRun.exe</p>
  
  <p>I googled but didn't find a solution to this, I would really appreciate it if someone could tell me what am I doing it wrong and how to fix it. Thank you so much in advance.</p>