I've stumbled upon some behaviour I do not understand. Consider the following function:
Function identity(n As Integer) As Integer
identity = n
End Function
Obviously this isn't the most practically useful function, but it highlights my problem well.
This works as I would expect, simply returning the input of it is an integer, otherwise throwing an error.
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'.
This also occurs if both the input and output types are changed to Objects.
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.
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...