title: Ask for comment on passing array element to a function in VBA
body: <p>I have the following VBA code:</p>
  
  <pre><code>Function InputElmt(element As Double) As Variant
      InputElmt = element
  End Function
  
  Sub runInputElmt()
      Dim arr() As Variant, Firstelmt As Double
      arr = Array(1, 2)
  
      Debug.Print InputElmt(arr(0) * 1)   ' 1st call
  
      Firstelmt = arr(0)
      Debug.Print InputElmt(Firstelmt)    ' 2nd call
  
      Debug.Print InputElmt(arr(0))       ' 3rd call: error
  End Sub
  </code></pre>
  
  <p>The sub calls the function <code>InputElmt</code> three times. The first two produce the correct results, while the last brings about an error (see <a href="https://i.stack.imgur.com/pkx9u.png" rel="nofollow noreferrer">compile error</a>).</p>
  
  <p>My interpretation is that the third call passes a string of <code>arr(0)</code> to the function rather than its evaluation. In contrast, in the first two calls <code>arr(0)</code> are evaluated.</p>
  
  <p>My questions are</p>
  
  <p>1) is my explanation correct? and</p>
  
  <p>2) is this error related to ByRef or ByVal as the error message might have indicated?</p>