Implicit Data Conversion

When the compiler encounters an assignment statement it will ensure that the data type of the variable being assigned matches the type of the value being assigned to it. If the two are not of the same type it will verify that the two types are compatible, that is, the compiler can implicitly convert the value into the variable data type. This is called an implicit conversion. If this is not the case a syntax error will be raised—the program is invalid (cannot be compiled).

For example the following code will compile and run correctly:

Dim i As Integer, d As Double
d = i

While the next lines of code will not compile:

Dim i As Integer, d As Double
i = d

You will notice the fact that d is underlined, and if you place ...

Get Visual Basic® .NET by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.