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
Guildford, Surrey, United Kingdom | Enstar
 IT Development Manager/IT Development Project manager - Guildford - £40k - £60k plus benefits   Enstar (EU) Limited (formerly Castlewood (EU) Limited) is seeking an IT Development Project Manager and an IT Development Manager to ... more >
London, Haringey, United Kingdom | Haringey Council
PMO Support Officer - Haringey, London - £32,289 - £37,542 pa   Experienced project support officer required by the internal IT services organisation of a London borough council to work within its Programme Management Office ... more >
Leek Wootton, United Kingdom | Warwickshire Police
 IT Business Analyst - Leek Wootton, Warwickshire - £29,112 - £31,491 PA - 37 hrs per week   Everyone who works for Warwickshire Police helps to protect our communities from harm. Work with us and ... more >
Oxford, Oxfordshire, United Kingdom | University of Oxford
Senior Business Analyst - Oxford University - £34,793 - £45,397   Business Services & Projects (BSP) Are you an experienced Business Analyst with the skills to improve the efficiency of Oxford University's business systems? The ... more >
More job opportunities