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

Converting to and from Strings

Of course, converting primitive data types isn’t restricted to numeric types. What’s more interesting is the conversion of a string into a numeric value or a date value, and vice versa. This is a very common operation, as most applications allow users to enter numeric values into TextBox controls, which contain strings, not numbers.

You can always perform the conversion by using the methods discussed in the preceding section. Here are a few examples:

Dim AStringWithDate As String = "24.12.2003"
Dim ADate As DateTime

ADate = CDate(AStringWithDate)
ADate = CType(AStringWithDate, DateTime)
ADate = Convert.ToDateTime(AStringWithDate)

Converting Strings by Using the Parse and ParseExact Method

There is another possibility ...

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