What's New in Visual Basic 15

WEBINAR:

REGISTER >

Visual Studio 2017 has finally been released and, oh, what a joy! With each release of Visual Studio, Microsoft raises the bar and technology that exists at the time gets a boost. I remember a time when Web Applications were the next 'big thing'! Now, with Visual Studio 2017, it is AI and Bots that are the new 'next big things'. It makes you wonder how the technology landscape will change in the next few years. With the new release of Visual Studio 2017, let's look at what's here today!

Visual Basic's Future: The Elephant in the Room

It seems as if Microsoft has no plans of forgetting about Visual Basic completely. On the contrary, Microsoft plans for Visual Basic to become a more distinguished language. In the past, Microsoft has spent a lot of time giving Visual Basic the same features as C#, and vice versa. Now, C# and Visual Basic are set to diverge. Going forward, Microsoft wants to quicken the pace of C# feature releases instead of holding off until a complete feature set in Visual Basic is also ready.

New in Visual Studio 2017

The focus of this article is Visual Basic 15, so I will mention just a few of the important improvements to Visual Studio 2017.

Visual Studio 2017 Installer

The big improvement in Visual Studio 2017 is the improved installer. The Visual Studio 2017 Installer is now a stand-alone app that you can always run again if you want to remove or add features. In the past, Visual Studio was mainly used to develop apps for a Windows platform. Times have changed and technology has changed. As you may be aware, with Visual Studio you can develop apps not only for Windows, but also for Android, iOS, the Web, and even Mac. The reason Visual Studio's installer has finally changed is because the install got too big, and, if you wanted to develop for other platforms, you would have had to install much more and the install process would have taken much longer.

The other problem was that people ended up installing a lot of unnecessary stuff that they didn't need and had no initial option of choosing their desired options properly.

Project Load time in Visual Studio 2017

Project and Solution load time has improved significantly in Visual Studio 2017, as well. Projects can be loaded in the background asynchronously, thus improving productivity time.

New Language Features in Visual Basic 15

Sadly, there aren't many new features in Visual Basic 15. This is likely due to the fact that C# 7 and Visual Basic 15 are going on separate paths. Here is a quick breakdown of the very few new language features in Visual Basic 15:

Visual Basic Value Tuples

A tuple is a data structure that has a specific number and sequence of values. In other words, tuples are a temporary grouping of values. Tuples are commonly used in different ways:

  • To represent a single set of data. For example, a tuple can represent a record in a database, and its inner components can represent that record's fields.
  • To provide easy access to, and manipulation of, a data set.
  • To return multiple values from a method without the use of parameters.
  • To pass multiple values to a method through a single parameter.

Here is a small example:

   Public Sub Main()
      Dim Ages() As Tuple(Of String, Nullable(Of Integer)) =
         { New Tuple(Of String, Nullable(Of Integer))("Hannes", 38),
         New Tuple(Of String, Nullable(Of Integer))("Ellie", 38),
         New Tuple(Of String, Nullable(Of Integer))("Kayla", 17)}
      Dim Age As Integer
      Dim AvgAge As Integer = ComputeAge(Ages, Age)
      Console.WriteLine("Average Age: {0:N2} (n={1})", AvgAge, Age)
   End Sub

   Private Function ComputeAge(Ages() As Tuple(Of String, _
         Nullable(Of Integer)), ByRef n As Integer) As Integer
      n = 0
      Dim sum As Integer
      For Each Age In Ages
         If Age.Item2.HasValue Then
            n += 1
            sum += Age.Item2.Value
      End If
      Next
      If n > 0 Then
         Return sum / n
      Else
         Return 0
      End If
   End Function
' The example displays Average Age: 31'

Visual Basic ByRef Return Consumption

ByRef return consumption supports consumption of functions and properties from libraries that have ByRef returns.

Visual Basic Binary Literals and Group Separators

Binary literals and digit group separators allow native representation of binary numbers.

Language Features that Were Left Out of Visual Basic 15

There are a couple of language features that were given to C# 7 that Visual Basic 15 did not get. These are worth mentioning here.

is-expressions

An is-expression checks whether an object is compatible with a given type in C#. For example, the following code can determine if an object is an instance of the TestObject type, or a type that derives from TestObject:

if (obj is TestObject)
{
}

out-variables

In previous versions of C#, before you can call a method with "out" parameters you first have to declare variables to pass to it. Because you weren't initializing the out variables, you also couldn't use var to declare them, but needed to specify the full type, as shown in the following example:

public void CheckSomething()
{
   int x;
   p.GetHorizontalLocation(out x);
   WriteLine($"({x})");
}

In C# 7.0, out variables are added with the ability to declare a variable right at the point where it is passed as an out argument, as in the following:

public void CheckSomething()
{
   p.GetHorizontalLocation(out int x);
   WriteLine($"({x})");
}

Local Functions

Local functions enable you to define a function inside the scope of another function. Local functions can be created in the body of any method, or any constructor or property's getter, and setter. This function then gets transformed to a regular private static method.

Conclusion

With each new release of Visual Studio, more and features get added to the languages we love. Although Visual Basic 15 didn't get as many new features as C# 7 this time around, next time might be different. With C# and Visual Basic going in different directions, who knows what Visual Basic is going to get and eventually evolve into?



About the Author

Hannes DuPreez

Hannes du Preez is an ex MVP for Visual Basic from 2008 to 2017. He loves technology and loves Visual Basic and C#. He loves writing articles and proving that Visual Basic is more powerful than what most believe. You are most welcome to reach him at: ojdupreez1978[at]gmail[dot]com

Related Articles

Comments

  • Portable EXE?

    Posted by Stephen Mann on 04/03/2017 10:54am

    Can VB15 publish a stand-alone executable? One that can be run on most PCs without installing VB...

    • Yes-ish

      Posted by Darryl on 04/10/2017 03:04pm

      VB (and C#) require that the .NET runtime be installed. VB15 will require .NET 4.7. I believe that .NET 4.7 will be automatically included with the next update to Windows 10. You haven't needed to install VB itself to run a VB program for 15 years or so.

      Reply
    Reply
  • Lots of errors in the post

    Posted by Dalibor Carapic on 03/31/2017 01:02am

    1. You are giving an example with standard reference Tuple class and not the new ValueTuple struct 2. 'is' expression is not new for C#, the only new thing is that it is usable in switch statements to perform map like operations. VB.Net does have the equivalent of 'is' operator, it is 'TypeOf'.

    Reply
  • Titled

    Posted by Bob Bingham on 03/28/2017 08:25am

    ?? Tuple has been around for some time. I'm looking at some VB.Net code from 2015 that uses it right now. MSDN docs say it has been around since Framework 4.0.

    • tuples

      Posted by Hannes on 03/29/2017 12:52am

      Hi Bob. Thanks for your interest. Yes, you are correct, I agree. Have a look here for information specific to VS 2017 https://blogs.msdn.microsoft.com/dotnet/2016/07/13/visual-studio-15-preview-3-for-c-and-visual-basic/

      Reply
    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date