title: VBA Object type
body: <p>I've stumbled upon some behaviour I do not understand. Consider the following function:</p>
  
  <pre><code>Function identity(n As Integer) As Integer
    identity = n
  End Function
  </code></pre>
  
  <p>Obviously this isn't the most practically useful function, but it highlights my problem well.</p>
  
  <p>This works as I would expect, simply returning the input of it is an integer, otherwise throwing an error.</p>
  
  <p>However, if I change the output to be an Object, I would still expect this to work, since, as I understand it, integers are objects. Alas, instead I get an 'error in Value'.</p>
  
  <p>This also occurs if both the input and output types are changed to Objects.</p>
  
  <p>The function exhibits truly curious behaviour when the input is changed to an Object but the output remains an integer. If it is called from excel via '=identity(3)' it errors, but if it is called via '=identity(A1)' where A1 contains 3, it returns the correct value.</p>
  
  <p>Can anyone explain what is going on? I'm new to VB, but I've programmed in many different languages previously and I've never seen anything like this...</p>