Learning the Visual Basic .NET Language (Page 1 of 9 )
This article presents an overview of the Visual Basic .NET language. It is excerpted from chapter three of the book
Beginning ASP.NET in VB.NET: From Novice to Professional, written by Matthew MacDonald (Apress, 2004; ISBN: 1590592786).
BEFORE YOU CAN CREATE an ASP.NET application, you need to choose a .NET language to program it. If you’re an ASP or Visual Basic developer, the natural choice is VB .NET. If you’re a longtime Java programmer or old-hand C++ coder, C# will probably suit you best. VBScript isn’t an option—it just doesn’t have the range, flexibility, and elegance a modern language demands.
This chapter presents an overview of the Visual Basic .NET language. You’ll learn about the data types you can use, the operations you can perform, and the code you’ll need to define functions, loops, and conditional logic. This chapter assumes that you’ve programmed before and that you’re already familiar with most of these concepts—you just need to see how they’re implemented in VB .NET.
If you’ve programmed with an earlier version of Visual Basic, you might find that the most beneficial way to use this chapter is to browse through it without reading every section. This approach will give you a general overview of the VB .NET language. You can then return to this chapter later as a reference when needed. But remember, though you can program an ASP.NET application without mastering all the language details, this deep knowledge is often what separates the casual programmer from the legendary programming guru.
NOTE The examples in this chapter show individual lines and code snippets. You won’t actually be able to use these code snippets in an application until you’ve learned about objects and .NET types. But don’t despair—the next chapter builds on this information, fills in the gaps, and presents an ASP.NET example for you try out.
The .NET Languages
The .NET Framework 1.1 ships with four languages: VB .NET, C#, JScript .NET, and J#. These languages are, to a large degree, functionally equivalent. Microsoft has worked hard to eliminate language conflicts in the .NET Framework. These battles slow down adoption, distract from the core framework features, and make it difficult for the developer community to solve problems together and share solutions. According to Microsoft, choosing to program in VB .NET instead of C# is just a lifestyle choice and won’t affect the performance, interoperability, feature set, or development time of your applications. Surprisingly, this ambitious claim is essentially true.
.NET also allows other third-party developers to release languages that are just as feature rich as VB .NET or C#. These languages (which already include Eiffel, Perl, Python, and even COBOL) “snap in” to the .NET Framework effortlessly. The secret is the special machine.config configuration file that is installed with the .NET Framework. In one of its sections, the machine.config file lists the language compilers that are currently installed.
<!-- Other configuration settings omitted. -->
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type= "Microsoft.CSharp.CSharpCodeProvider, System, Version=1.0.5000.0"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type=
"Microsoft.VisualBasic.VBCodeProvider, System, Version=1.0.5000.0"/>
<compiler language="js;jscript;javascript" extension=".js"
type= "Microsoft.JScript.JScriptCodeProvider, Microsoft.JScript,
Version=7.0.5000.0"/>
<compiler language="VJ#;VJS;VJSharp" extension=".jsl"
type= "Microsoft.VJSharp.VJSharpCodeProvider, VJSharpCodeProvider,
Version=7.0.5000.0"/>
</compilers>
TIP To view the machine.config file, look for the directory [WinDir]\ Microsoft.NET\Framework\[Version]\Config. For example, after installing .NET 1.1 on a Windows XP computer, the machine.config file is placed in the directory C:\Windows\Microsoft.NET\Framework\v1.1.4322\Config.
To install another .NET language, all you need to do is copy the compiler to your computer and add a line to the machine.config file. (Typically, a setup program will perform these steps for you automatically.) The new compiler will then transform your code creations into a sequence of IL (Intermediate Language) instructions.
IL is the only “language” that the CLR recognizes. When you create the code for an ASP.NET web form, it’s changed into IL using the VB .NET compiler (vbc.exe), the C# compiler (csc.exe), the JScript compiler (jsc.exe), or the J# compiler (vjc.exe). You can perform the compilation manually or let ASP.NET handle it automatically when a web page is requested. We’ll discuss the difference between these two techniques in Chapter 5.
Next: The Evolution of VB .NET >>
More Visual Basic.NET Articles
More By Apress Publishing
|
This article is excerpted from chapter three of the book Beginning ASP.NET in VB.NET: From Novice to Professional, written by Matthew MacDonald (Apress, 2004; ISBN: 1590592786). Check it out at your favorite bookstore today. Buy this book now.
|
|