Hi guys,
First of all, I have to agree with Duh on his comment:
VB does compile the example Duh posted when you would think it obviously shouldnt, but there are reasons why it does compile.Quote:
what is the point of having types in the arguments of a function if they are not used to help the coder avoid passing incorrect things to functions before it is run
VB 4.0 introduces the concept of "automatic type coercion". Apparently it makes code more efficient, but what it means is that variables of certain data types can automatically get converted to other types without you having to convert it explicitly. Integers to Booleans, Strings to Dates, Strings to Numbers, etc. There are rules that get followed by VB with these coercions.
Obviously this isnt going to be everyones preferred coding approach, but its built into the fabric of VB and thus needs to be maintained for eternity to allow backward compatibility.
Anyway, the fact of the matter is that assigning a string to a integer is considered "legal" by the compiler due to these coercion rules, i.e., the string "1234" can be coerced to the number 1234, but the string "abcd" cannot, so its not until the code is actually executed that it realises that the text "abcd" is not really a number, and it then becomes a runtime error and not a compiler error. So compiling your code into an executable is allowed, but when you run it, you get a type mismatch runtime error.
Make sense?
Its not very strong type casting, and I am not sure if I agree with the whole idea of it myself ... you have CStr() CInt() CLng() etc, if you want to convert your data types, and I dont like VB making assumptions for me ... but for others it probably makes life alot easier.
So there you have it ... you are all smarter now :D
Cheers,
Tinbum747
