Screenshot of Visual Basic Express editions
Grab the free Visual Studio 2008 Express editions to explore the latest Visual Basic
R E L A T E D   C O N T E N T
ADVERTISEMENT

Hands on: Virtual Basic in 2008

Find out what the new year holds for Visual Basic programmers

Tim Anderson, Personal Computer World 21 Mar 2008
ADVERTISEMENT

Microsoft’s Visual Basic 2008, also known as VB 9, is the third version to be based on the .Net Framework.

An added bonus is that the Express variant is free, unrestricted, and co-exists with earlier versions. With .Net established, Microsoft is evolving the language with important changes.

Perhaps the first thing to get your head round is type inference. The idea is that typing Dim i As Integer = 3 is a waste of space.

The compiler can see that 3 is an Integer, so it can infer the type. In VB 2008, if you type Dim i = 3 then the variable will be assigned the Integer type. This is at compile-time, not at runtime, so it is the same as strong typing.

Type inference only applies to local variables, and only when declared and assigned in the same statement. It could break existing code, if you were relying on VB to declare untyped variables as objects, but such errors are easy to fix.

Another space saver is called relaxed event handlers. In VB 2005, every event handler has arguments for sender and EventArgs, like this: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

In VB 2008, you can have this instead: Private Sub Button1_Click() Handles Button1.Click
It is another step towards uncluttered code, which is a good thing.

Other new language features include Object Initializers – which means you can create an object and set its properties in the same statement – as well as Anonymous types, Lambda expressions, and Extension methods.

Although interesting, they are also part of the plumbing behind the headline feature, Linq (Language Integrated Query). Linq brings database queries into the language, so there’s no need to assemble SQL strings.

Use XML literals
New in VB 2008 is native XML. This looks strange, as it breaks assumptions about how code is separated from data. This is now valid VB 9 code:
Dim theItems = _
<posts>
<myitem title=”First item” desc=”Some text” link=”http://someurl”/>
</posts>

The above code uses type inference to create a variable of type XDocument. It is interesting, but not yet useful. The value becomes apparent when you combine it with another feature called embedded expressions. Here’s how you can use this to transform the XML snippet above to a valid RSS feed.


All Software Applications

Like this story? Spread the news by clicking below:

Post this to Delicious del.icio.us    Post this to Digg Digg this    Post this to reddit reddit!

Permalink for this story
R E A D E R   C O M M E N T S
M A R K E T P L A C E
Get your free demo of Numara Track-It! 8 - the leading help desk solution for IT related issues.
Make presentations, review documents & share your entire desktop. 30-day free trial! (cc required).
Discover how remote support can fuel your IT business in ways you've never thought of before.
Apply ITIL best practices at your service desk while eliminating integration cost. Learn more here.
WAN based, automated, daily vulnerability assessments. Click here to try and request our whitepapers.
Have your product or service listed here >   
Sponsored links
F E A T U R E D   J O B S
| Aston Carter
C++ Market Data Developer - Unix - Java - SQL My client are a top financial software house based in the city. They are currently seeking a C++ developer to work in their market data ... more >
| Aston Carter
Junior Python Developer - SQL - Functional Programming - Javascript - Django - Perl - Ruby - MVC My client are a startup software house that specialise in online gaming. The team is small and ... more >
| Aston Carter
Required: Salesforce CRM, Excel My client are Britain's leading financial spread betting firm and are the world's leading trading platform for private investors. This is an excellent opportunity for Salesforce Administrator to join a leading ... more >
| Aston Carter
C# Developer, Hedge Fund, Algo Trading, London The role is working for a boutique derivatives trading company who focus on options high frequency algorithmic trading. They are looking for a bright junior Microsoft .net developer ... more >
More job opportunities