Share via


This article may contain URLs that were valid when originally published , but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.

MIND

The Future of Visual Basic: Web Forms, Web Services, and Language Enhancements Slated for Next Generation

Joshua Trupin
This article assumes you're familiar with Visual Basic
Level of Difficulty    1   2   3 

SUMMARY The plans for the next version of Microsoft Visual Basic include three major improvements: Web Forms, Web services, and object-oriented language enhancements. Web Forms will let veteran Visual Basic users develop Web-based applications as easily as they design standalone apps today. Through a SOAP interface, Web services will let you deploy programmable modules anywhere that can be reached by a URL. In addition, several key object-oriented language enhancements, including inheritance, polymorphism, and overloading, will make Visual Basic code as flexible as C++. See Steve Ballmer's VBITS keynote on the next generation of Visual Basic at https://msdn.microsoft.com/vstudio/nextgen/keynote.asp.

V

isual Basic® has undergone a decade of evolution and adaptation. One of the things I've liked about the language since its earliest incarnation is that, at its core, you can still write programs just the same way as you could in 1991. There have been many improvements to the package since then, but they have usually complemented rather than obscured the original purpose of the development tool itself—making it simple to rapidly design, develop, and deploy outstanding object-oriented applications.
      Visual Basic 6.0, the current version of the package, introduced WebClasses as a simpler way to deploy robust, server-based Web applications. Indeed, WebClasses produced a surprisingly scalable way to use a familiar tool to migrate programs to the Web. (For a lengthier discussion on the scalability of Visual Basic 6.0 in a Web environment, check out Ted Pattison's Advanced Basics column in the November 1999 issue of Microsoft Internet Developer, or at https://www.microsoft.com/mind/1199/basics/basics1199.htm)
      I recently had a chance to see some of the upcoming improvements planned for the next version of Visual Basic. The major improvements that are in store for developers are threefold. It is planned that Visual Basic will share with Visual Studio® a feature called Web Forms. Web Forms represent a completely new approach toward providing a componentized Web solution. Web Services will be a new, XML-based way to expose middle-tier business functionality via standard Web protocols. At the same time, the Visual Basic language will include several constructs developers have long asked for that will bring it in line with the kind of object-oriented programming techniques familiar to users of C++ and the Java language.
      These innovations will not be available to the public until the next version of Visual Basic is in beta. I'll offer you some code snippets here, but not a complete project. So why worry about this now? Quite simply, there are specific ways you can architect your applications and implement best practices today, helping make a smoother transition if and when you decide the new capabilities are for you. And even if you don't, you won't lose out if you structure your upcoming projects based on the guidelines I'll discuss near the end of this article.

Visual Studio Web Forms

      The next release of Visual Basic, as part of Visual Studio, will likely introduce a new concept, the Web Form, for Web developers. The purpose of Web Forms will be to extend the RAD capabilities of Visual Basic to encompass the broad reach of a Web application. Developers using any of the languages in Visual Studio will be able to use these shared Visual Studio Web Forms.
      A Web Forms page exists in two parts: an HTML file representing the visual representation of the page, and a source file that handles the page's events. Since almost a third of Visual Basic-based development today is targeted at the Web, Microsoft plans to enhance these capabilities further. With the next version of Visual Basic, you'll be able to design a Web Form much as you would create a form in Visual Basic today. You'll have a palette of Web controls you can drag to the HTML designer, then set properties on them and write appropriate code (see Figure 1). In short, you'll be able to do exactly what you've always done in Visual Basic to create a form. You'll have full IntelliSense®, WYSIWYG form design, and compiled code. So if you know how to write an application in Visual Basic, Web Forms will make you into a Web developer without changing the way you work.
Figure 1 Building a Web Form in Four Steps
Figure 1 Building a Web Form in Four Steps

      Web Forms run on the server and pass only the HTML-based form down to the client. Just as an Active Server Page (ASP) page isn't browser-specific, neither is a Web Form-based application; the processing is performed on the server. In effect, you're running a program that generates a remote user interface with HTML 3.2. Unlike an ASP page, the code is compiled instead of interpreted, so speed is much improved.
      Web Forms are designed to provide the best parts of both the ASP and the WebClass model. You can create them with any language in the Visual Studio family, so you'll be able to use what you already know to create fast, server-based Web applications.

Web Services

      Web services represent the second major improvement slated for the Visual Studio development system. In a nutshell, a Web service is a middle-tier business function that's exposed via standard Web protocols. They can communicate through firewalls since they use HTTP as a transport mechanism (see Figure 2). You'll be able to build multiple Web services into a Web app simply by pointing to the appropriate URL. At runtime, all the intercomponent calls will automatically be packaged and handled through an XML interface. Developers can create and use Web services on any platform, in any language. If you need security, you'll be able to use Secure Socket Layer (SSL) or standard authentication techniques.
Figure 2 Web Services Architecture
Figure 2 Web Services Architecture

      If this is already starting to sound a bit familiar, it's with good cause. The mechanism used to pass data from one component to the next is SOAP—the Simple Object Access Protocol. Don Box covered SOAP extensively in the March 2000 issue of MSDN™ Magazine (https://msdn.microsoft.com/msdnmag/issues/0300/soap/soap.asp).
      The goal of all these new features is to let Web developers build applications more quickly by assembling them from existing, reusable Web services instead of recreating functionality each time out. This is going to usher in a new era of code library providers and innovation.
      With the next version of Visual Basic, you'll be able to quickly implement and expose any function in a particular project as a Web service. You're probably familiar with the process of setting a function in a Visual Basic class as public. There will be a new function tag, tentatively named webpublic, that will indicate that the procedure is to be exposed as a service—not just with a COM interface to any local object that's interested, but to any Web application that references its URL. Just as you can add a reference to a public object in a new project, you'll be able to add a reference to a Web service and use it as if it existed locally.
      Of course, the mechanism will be somewhat different. Visual Basic can dereference local objects through their COM interfaces. When you add a Web service reference to your application, an interface definition will automatically be created by the remote object and sent to Visual Studio by way of SOAP. Although this will be generated as XML, you won't need to do any plumbing of your own—Visual Basic will handle it for you. Receiving this interface definition allows you to use IntelliSense as you start to write code that references the object.
      Here's a simple example. At some point, you might create a function called Seahawks. Maybe the function looks like this:

  
Public Function Seahawks(ByVal opponent As String) As String
    Seahawks = "lose"
End Function

      When you build the project containing this function, Visual Basic will automatically create an XML description of this function and publish it to the Web:

  
<?xml version='1.0' ?>
<methods href='https://julian/Football/Teams'>
    <method name='Seahawks' href='Seahawks'>
        <request>
            <param dt='string'>opponent</param>
        </request>
    <response dt='string'/>
    </method>
</methods>

      The XML file will be used to describe the Seahawks function. If you're using Visual Studio, you'll be able to drag any exposed Web service right into your application, creating a new class file. If you want to call a Web service anywhere on the Internet, all you'll need to do is create a new instance of the Web service class and call its exposed methods.
      When the Seahawks function is called, it will automatically communicate through XML packets. If you're using Microsoft® Internet Explorer 5.0 (with its integrated XML support), you can try out the function right in your browser. You can call the function with a URL such as https://julian/webservice1/component1.methods/Seahawks?opponent=Miami. This call will return data in the following XML format:

  
<?xml version="1.0" ?>
<Response>lose</Response>

      To facilitate the creation of Web services, Visual Basic is expected to introduce a new type of project, cleverly called a Web Service. You'll be able to design and deploy your Web Service to a remote server as easily as you would create a local DLL today.

Language Improvements

      For what seems like forever, there's been a natural tension between developers who are partial to Visual Basic and those who prefer a more "comprehensive" language like C++ or Java. More than once, I've had to defend my favorite programming language from charges that it was somehow a toy language because it lacked certain OOP features.
      Well, guess what? The next version of Visual Basic should finally put those complaints to rest. Microsoft plans to introduce the big three of object-oriented programming: inheritance, polymorphism, and overloading. And that's not all! Other new constructs, including structured error handling and freethreading, will be introduced to the language.
      Inherited functions save time and improve reusability by allowing you to design a base class, then write classes that inherit the functionality of the original. For instance, you might write a base class called BaseClass with a single function like this:
  
Function GetCustomerName()
' Do some stuff
End Function

      Now you want to write a second class that uses this GetCustomerName function as well as implementing new functions of its own. What was the old way to do this? Well, there was no old way. The new way, however, is to insert a simple line at the top of the new class like so:

  
Inherits BaseClass
Function GetCustomerID()
' Do some stuff
End Function

      Overloading is the process of creating two or more functions with the same name, but with different function signatures. In a way, Visual Basic already does this for you when it performs implicit type conversions on function calls and property settings. Consider these two lines of valid Visual Basic code:

  
Text1.Text = "7"
Text1.Text = 7

In each of these calls, the text in Text1 will be set to the string "7". This is an overloaded call because it knows how to handle various data types thrown at it, treating them as variants and automatically converting them. Visual Basic also converts arguments when you pass them to an explicitly typed function. These two function calls

  
a = SetVal("This")
a = SetVal(7)

both work properly with this function:

  
Function SetVal(x As String)
    Form1.Text1.Text = x
End Function

      So if Visual Basic already lets you pass multiple variable types to a function, why the need for overloaded functions? While a single function can handle multiple data types today, it can't react differently depending on the data type that's passed in. Instead, consider these two functions:

  
Function GetCustomerID(custname as string) As Integer
' Look up customer ID based on customer name
End Function
Function GetCustomerID(purch as long) As Integer
' Look up customer ID based on purchase order
End Function

      With overloading, you'll be able to implement functions that react differently based on input type. This will be important because of another planned feature of Visual Basic—default type safety. While auto-conversion of variables is often a handy feature, it can conceivably get you into trouble. In the previous SetVal example, what if you meant to pass in character code 7, not the string "7"? The next version of Visual Basic will catch this and throw an error by default. (This feature can be disabled if you have code that relies on previous typeless behavior in Visual Basic.)
      Finally, polymorphism is the process of redefining functions within defined classes. For example, you might want to write a derived class that inherits BaseClass, but you want to rewrite the GetCustomerName function. In the next version of Visual Basic (and remember, all final syntax is subject to change in the shipping version), you'll be able to implement a new class that looks something like this:

  
Inherits BaseClass
Function GetOrders()
Overrides Function GetOrders()
•••
End Function

More Language Features


      The next version of Visual Basic will likely provide several language features beyond the object-oriented improvements I just described. With an eye towards scalability and reuse, there will be new options for thread creation, error handling, and various long-needed language enhancements.
      Visual Basic currently supports an apartment-threaded model. While this model provides some real efficiency to deployed apps, it stops short of ideal. The next version of Visual Basic is expected to improve on this, offering a freethreaded model that will really make a difference when you're writing scalable Web applications. Visual Basic will include language constructs that let you spawn multiple threads. A typical thread-spawning operation might look like this:
  
set t = New Thread(New Threadstart
                  (AddressOf(BaseClass.Function1))

      As you can see from this example, the next version of Visual Basic is slated to have an AddressOf construct that will return the address of a function. No longer will you be forced to ignore API functions that need a function pointer! If you need to provide a callback, you'll be able to do it.
      Another improvement in planning is structured error handling. Right now, Visual Basic makes you stick a bunch of On Error statements in your code. And for years, I know I've felt guilty putting in all those GOTOs. They told me in tenth grade not to use them! Let's face it—the error handling features leave something to be desired.
      The next version of Visual Basic is slated to offer centralized error handling. Visual Basic will support a try…catch…finally construct, just like those "respectable" languages. You'll be able to put a subroutine at the top of your code and let the errors bubble up into it. Here's an example of how structured error handling will be implemented:

  
Sub SafeWrite()
Try
  Open "Testfile"
•••
  Write #1
Catch
   Kill "Testfile"
Finally
   Close #1
End Try
End Sub

      There are a few other miscellaneous improvements that should quickly become natural to existing users of Visual Basic. The next version will allow you to initialize variables on the same line on which they're declared:

  
Dim a as integer = 10

You'll be able to create and initialize new objects all in a single expression. You'll also be able to share variables across classes. Last, but not least, the inheritance concept will be extended to the user interface elements of a project. One repeated comment about Visual Basic has been that it's hard to create multiple forms with identical elements on them. (This is a frequent requirement in a corporate environment.) With the next version of Visual Basic, you should be able to do just this with template forms.
      People have been asking about many of these improvements for years—so why now? Let's face it, the Visual Basic community (of which I've been a part for almost a decade) has become far more sophisticated since the first release of Visual Basic in 1991. Early on the language was primarily used for rapid prototyping and the development of small, handy utilities. As a result, Visual Basic earned a reputation (undeserved, in my eyes) as a toy. Well, it's obviously not a toy today—anyone who would tell you that is speaking from a position of language bigotry. Today there are thousands of large-scale deployments of Visual Basic-based packages. Visual Basic is on the move. At a focus group last year, I spoke to a developer who has implemented a WebClass-based solution that easily serves a million hits a week.
      The nice thing about the changes slated for the next version of Visual Basic is that they're incremental; you can use them if you want to reap their benefits. If you don't, you can just keep doing what you're doing today with no penalty. However, it's good to know that the power of a language like C++ or Java is available within a language that's easier to use.

Preparing for the Future

      Where does this preview leave you today? That's a good question, but there is an answer. Over the past year, there's been a visible shift away from early ASP development efforts, which frequently consisted of humungous ASP scripts running an entire program. Since ASP interprets script code, people started to discover the inherent limitations of a technology that was designed to tie components together. I've heard from more and more developers who have migrated their business functionality out of script code completely, putting it in faster, compiled modules that are written in C++ or Visual Basic and tied together through COM interfaces.
      This is definitely the way to go, for just about every reason you can imagine. Using Visual Basic to design a component is really no harder than using VBScript or JScript®. You'll create faster code, it'll be easier to scale with your needs, and when the next version of Visual Basic is released, you'll be able to use it to create Web-based objects that are glued together with ASP. In general, going the components-and-glue route should be considered a best practice for now and the future.
      As I mentioned earlier, there's a significant installed base that uses Visual Basic (and WebClasses) to create Internet-ready applications today. The problem is, most WebClass-based applications are not well-architected. They don't separate the different tiers of the application well, mixing middle-tier processing with DHTML-based user interface.
      The changes scheduled for the next version of Visual Basic will probably supplant WebClasses as the Web development method of choice, since they're more scalable, more powerful, and are actually language-agnostic—they'll work across the spectrum of Visual Studio tools. The transition will be a lot easier if you pay attention to the basic rules of multitier development. Specifically, keep middle-tier processing separate from the display layer. It is strongly recommended that you do this by following the Windows® DNA 2000 architecture. Core business functionality should end up in a middle-tier component that's authored in your favorite compiled language. These components, in turn, can be tied together in an ASP file with just enough script to allow the various elements to work together. If you keep most of your logic in the business objects and not in script, you'll be better off. It's not just a good idea for a future transition to Web services, it's a good practice to follow in general.
For related articles see:
https://msdn.microsoft.com/vstudio/nextgen
https://msdn.microsoft.com/msdnmag/issues/0300/soap/soap.asp
Background information:
https://msdn.microsoft.com/vbasic
https://www.microsoft.com/dna
https://msdn.microsoft.com/xml/default.asp

Joshua Trupin is a technical editor for MSDN Magazine. He has written numerous articles for MSJ and MIND, the predecessors to MSDN Magazine, as well as a book, Hoop Stats: The Basketball Abstract. He lives on Long Island with his wife, two children, two dogs, and four pet CHUDs that followed him home one night.

From the April 2000 issue of MSDN Magazine.