This is more of a curiosity question on what the VB compiler is doing. Basically the following code generates an error,
If "String" = CInt(1) Then
End If
As it should. What makes me curious is the error reported is
Conversion from string "String" to type 'Double' is not valid.
So, I guess my question is, why is the compiler attempting to convert to a Double when i would assume it should be converting to Integer?
Following can give some hint.
For following
The innerexception stacktrace shows
Even if you change the statement as
If "String" = CDbl(1) Thenor
If "String" = CDec(1) ThenIt still shows the innerexception stacktrace as given above.
It means it has to do nothing with the right hand side value. It is behavior of compiler while doing implicit conversion to convert the string to more accommodating data type which is double(long would be too long-pun intended ).
This behavior can be proved by changing the statement to :
For this the innerexception stacktrace shows
Which means even for explicit type conversion it first tries to convert the string to double(most accommodating) and then converts it to integer.