IIf statement - I don't understand the behavior in this context.
Why would returnsInt return a 0 every time? I was thinking it should return 4 both when the boolean was true and false. The reason i ask is that I am reading through someone else's code and to understand it I tried emulating it. If it were up to me, I'd be using return statements.
thanks for your help,
Phil
Edit: I now think it's because the IIf statement returns a value, and thus is being used incorrectly in this case. Is there a version of vb where the above code works as the programmer intended? I know this guy is older than me, so he might be used to coding in an older version.
VB.NET:
Private Function returnsInt() As Integer
IIf(False, returnsInt = 2, returnsInt = 4)
End Function
public sub main()
MsgBox(returnsInt())
end sub
Why would returnsInt return a 0 every time? I was thinking it should return 4 both when the boolean was true and false. The reason i ask is that I am reading through someone else's code and to understand it I tried emulating it. If it were up to me, I'd be using return statements.
thanks for your help,
Phil
Edit: I now think it's because the IIf statement returns a value, and thus is being used incorrectly in this case. Is there a version of vb where the above code works as the programmer intended? I know this guy is older than me, so he might be used to coding in an older version.
Last edited: