Pages

Wednesday, August 29, 2012

Import the VisualBasic namespace to access some legacy features (VB .NET)

In a recent tip, we reported that you can no longer access the Left and Right string functions in Visual Basic .NET. As many of our subscribers pointed out, that isn't entirely true. While these functions aren't a part of .NET's String class, you can still access them by importing the Visual Basic namespace.

To do so, place: Imports Microsoft.VisualBasic, at the top of your class and then you can use code similar to the following to use the legacy functions:

Dim myString As String = "Visual Basic"
MsgBox(Strings.Left(myString, 6))
MsgBox(Strings.Right(myString, 6))

Thanks to all those who pointed out our error.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.