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

Type Literal for Determining Constant Types

Type literals force a constant to be a certain type. (Thus, in my opinion, I think they should be called “Type forcing literals for constants.”) You have already learned about type literals in several examples. To assign a string to a variable, you define it as having the type String, and put whatever you would like to assign to it between quotes, as illustrated here:

Dim AText As String = "Put in quotes"

You don’t do this for numeric variables, however:

Dim Pi as Double = 3.1415926

To force a numeric constant to be a string so that you can assign it to a String variable without having to convert it, you also place it in quotes. Quotes turn a number into a string:

Dim PiAsText As String="3.141592657"

Be aware ...

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