New Features in Visual Basic 9.0

Will the New Additions to Visual Basic Help Regain Lost Ground?

Joydip Kanjilal

October 30, 2009

4 Min Read
ITPro Today logo

asp:Feature

LANGUAGES: C#

ASP.NET VERSIONS: 2.0

 

New Features in Visual Basic 9.0

Will the New Additions to Visual Basic Help Regain Lost Ground?

 

By Joydip Kanjilal

 

Visual Basic has been one of the most popular programminglanguages to date. Granted, it was losing its popularity and was about to fadeoff. But just when it seemed that it was the end of the road for one of themost popular programming languages ever, Microsoft has put in a host of newfeatures in Visual Basic 9.0, which ships with VS.NET2008. MSDN states, Visual Basic has always centered on building pragmatic,data-oriented, line of business applications. While the move to .NETbrought the power of a unified framework and a managed platform to theapplication developer, the next release of Visual Basic includes a set offeatures that result in a profound effect on a developer s productivity whenbuilding data-oriented applications. These language extensions introducegeneral-purpose query facilities that apply to all sources of data, be it relational,hierarchical object graphs, or XML documents.

 

This article takes a look at these additions to VisualBasic.

 

So, What s New?

In this section we ll take a look at some of the mostimportant features that have been added to Visual Basic. Here s a list of the additionsto Visual Basic:

  • Support for LINQ

  • Lamda Expressions

  • Nullable Types

  • Partial Methods

  • Extension Methods

  • Object Initializers

 

The new version of Visual Basic supports LINQ, a new additionto Microsoft .NET Framework 3.5. Here s a code snippet that illustrates how youcan query data using LINQ and VB.

 

Dim Employees = {New Employee With { .Code = 1, .Name ="Joydip"}, _

New Employee With {.Code = 2, .Name = "David"}}

 

And, now, you can query as shown in this code snippet:

 

Dim query = From Employee In Employees Select Employee

For Each Employee In query

 Console.WriteLine(Employee.Name)

Next

 

You can use Lambda expressions to define a namelessfunction, then use it as shown in the code snippetbelow:

 

Dim result = Function(myNumber) Math.Pow(myNumber, 1 / 3)

 MsgBox(result(8))

 

Nullable types allow you to assign null values to valuetypes. You can find more about Nullable types in my article at: http://www.devx.com/dotnet/Article/35621.

 

You can define a Nullable type in Visual Basic in one ofthe following three ways:

 

Dim flag? As Boolean

Dim flag As Boolean?

Dim flag As Nullable(Of Boolean)

 

The Boolean variable flag can accept one of these values:True, False, or Nothing. You can then use the type in the same way you useother types. Here s an example:

 

If flag Then

   MsgBox("True")

       ElseIf Not marriedThen

   MsgBox("False")

       Else

   MsgBox("Un-defined")

End If

 

Now, if the Boolean variable flag is set to a value of Nothing ,the message Un-defined will be displayed.

 

And, here s another example:

 

Dim Employees = New Employee With {.Code = 1, .Name ="Joydip", .PF = Nothing }

 

Recall that you had Partial Classes in the earlier versionof Visual Basic. Now we have Partial Methods, as well.

 

Also, there are now anonymous types to define your typewithout having to define your class. Awesome, isn t it? Here s how you can doit:

 

Dim objEmployee = New With { .ecode = 12, .ename ="Joydip"}

 

Object Initializers enable you to initialize an object atthe time it is instantiated. Here s how you can use Visual Basic to initializean object using its properties at the time you instantiate:

 

Dim myObject = new MyClass with {.a = 100, .b = 200, .c = 300}

 

Conclusion

This article has had a look at the some of the mostimportant features in the new version of Visual Basic that have been introducedas part of Visual Studio 2008. It is just the beginning; let s hope more willcome and help Visual Basic regain its popularity and gain community respect. Pleasesend me your comments. Happy reading!

 

Joydip Kanjilal isa Microsoft MVP in ASP.NET. He is the authorof ASP.NET Data Presentation Controls Essentials (Packt Publishing; http://www.packtpub.com/asp-net-data-presentation-controls/book).He has more than 12 years of industry experience in IT with more than six yearsin Microsoft .NET and its relatedtechnologies. He has authored articles for some of the most reputable sites,like http://www.asptoday.com, http://www.devx.com, http://www.aspalliance.com, http://www.aspnetpro.com, http://www.sql-server-performance.com,http://www.sswug.com, etc. Many of thesearticles have been selected at http://www.asp.net(Microsoft s Official Site on ASP.NET).Joydip also was a community credit winner at http://www.community-credit.com anumber of times. He is currently working as a Senior Consultant in a reputablecompany in Hyderabad, India. He has years of experience in designing andarchitecting solutions for various domains. His technical strengths include C,C++, VC++, Java, C#, Microsoft .NET, AJAX,Design Patterns, SQL Server, Operating Systems, and Computer Architecture.Joydip blogs at http://aspadvice.com/blogs/joydipand spends most of his time reading books, blogging, and writing books andarticles. His hobbies include watching cricket and soccer, and playing chess.Contact Joydip via e-mail at mailto:[email protected]and view his MVP profile at https://mvp.support.microsoft.com/default.aspx/profile/joydip.

 

 

 

 

Read more about:

Microsoft
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like