November 24, 2014
Hot Topics:

An Orcas Preview: Go Inside the Next Version of VB

  • July 7, 2006
  • By Josh Fitzgerald
  • Send Email »
  • More Articles »

Nullable Types

Relational databases allow null values for all kinds of data types. Most programming languages have no built-in facility for handling null values. For example, a variable of type Integer in VB must always have some value; it can never be Nothing. To address this problem, the CLR has added support for nullable types. To declare a variable as nullable in VB 9, you must put a ? at the end of either the variable name or the type name.

Now, modify the Employee class to contain a StartDate and an EndDate. StartDate is obviously the date an employee started working, and so it will never be Nothing. However, EndDate will not have a value until an employee no longer works for the company, so it will be Nothing until then. The new version of the Employee class looks like this:

Class Employee
   Public Property Name As String
   Public Property ID As Long
   Public Property Department As String
   Public Property StartDate As Date
   Public Property EndDate As Date?
End Class

You also could write the EndDate declaration as follows:

Public Property EndDate? As Date

To create and initialize a new Employee object, you can do this:

Dim e = New Employee {
            .Name = "Joe Smith", _
            .ID = 123456789, _
            .Department = "Accounting", _
            .StartDate = #1/1/1995#, _
            .EndDate = Nothing
        }

As you can see, this is very useful because you no longer have to use some arbitrary date in the distant past or far future (in other words, 1/1/1900 or 12/31/3000) as a null value. It also allows objects to more closely represent the data they are based on and frees the programmer from having to worry about translating null values between the database and the application.

Find Out More

Visual Basic 9 will offer many new exciting features, especially in the areas of data access and management. I believe the planned improvements will make a great language even better. I'm excited to see Microsoft putting so much effort into VB and trying to make developers' lives easier. Although this preview has touched on only a few of my personal favorite new features, I hope it has enticed you to further explore what's coming in VB 9.

What's in a Name?

For those of you curious about the Orcas codename, Microsoft names early versions of products after geographical features in the northwestern United States. Orcas, and its older sibling VB 8 (codename: Whidbey), are both islands located off the coast of Washington.

About the Author

Josh Fitzgerald is an applications development group leader for a large medical device company in Warsaw, Indiana. Designing and developing Visual Basic .NET applications is only one of his responsibilities, but it is his favorite part of his job. You can reach Josh at josh.fitzgerald@gmail.com.





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel