O'Reilly logo

Microsoft® Visual Basic® 2010 Developer’s Handbook by Klaus Löffelmann and Sarika Calla Purohit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing Type Conversion Operators for Use with CType

Type conversion operators are double-edged swords. They definitely increase the degree of convenience, but they can also lead to tremendous problems—you’ll see more about these problems later.

To recap: you can use an implicit conversion to convert a small data type into a larger data type—for example an Integer value into a Long value, as demonstrated here:

'Here you can use an implicit conversion (type extended)
Dim aLong As Long, anInteger As Integer
anInteger = 10
aLong = anInteger

However, the Visual Basic compiler initially blocks a type conversion into a smaller type—at least until you explicitly finagle your way out of the situation with CType or a special Cxxx operator. Keep in mind ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required