Programming Microsoft Visual Basic .NET Version 2003 ... - doc serve

docserve.files.wordpress.com

Programming Microsoft Visual Basic .NET Version 2003 ... - doc serve

12 Part I: The Basics

language. Developers who know both Visual Basic .NET and C# (and possibly other

languages as well) will undoubtedly have more job opportunities, so .NET is also a

great opportunity for all professionals and consultants. I believe that all Windows

developers should start working with the new version of the language they know better—Visual

Basic .NET if they’ve worked with Visual Basic 6, or C# if they’ve worked

with C++ or Java—and then learn the other language as soon as they feel comfortable

with the .NET way of doing things.

The Visual Basic .NET Compiler

Before we continue with our exploration of the .NET world, let’s create our first Visual

Basic program, compile it, and run it. In the process, you’ll learn several interesting

things about the .NET architecture. In this first example, I use Notepad to create a simple

program and the command-line vbc.exe compiler to produce an executable. In

most real cases, you’ll use Visual Studio .NET and its integrated editor, but I don’t want

you to be distracted by that environment during this first experiment.

Launch Notepad (or any other text editor), and type the following code:

Module Module1

Sub Main()

Dim x As Double, res As Double

x = 12.5

res = Add(x, 46.5)

System.Console.Write(“The result is “)

System.Console.WriteLine(res)

End Sub

Function Add(ByVal n1 As Double, ByVal n2 As Double) As Double

Add = n1 + n2

End Function

End Module

Even though the syntax is different from Visual Basic 6, it should be clear what this

program does. The only new statements are the calls to the Write and WriteLine methods

of the System.Console object, which send their argument to the console window.

(The WriteLine method also appends a newline character.) Save this source file with

the name Test.vb, next open a command window and move to the directory in which

you saved the Test.vb file, and then run the VBC compiler and pass it the Test.vb file.

The vbc.exe file is located in this directory:

C:\Windows\Microsoft.NET\Framework\vx.y.zzzz

where Windows is the main Windows directory and x.y.zzzz is the complete version

number of the runtime in use. Version 1 of the .NET Framework has a complete version

number 1.0.3705, whereas the .NET Framework version 1.1 corresponds to version

number 1.1.4322. For example, on my system this is the command I have to type to run

the Visual Basic 2003 compiler:

C:\Windows\Microsoft.NET\Framework\v1.1.4322\vbc Test.vb

More magazines by this user
Similar magazines