Hello, World

 < Day Day Up > 

Hello, World!

By long-standing custom, the first example in any programming language book is the following program.

 Module HelloWorld   Public Sub Main()     Console.WriteLine("Hello, world!")     Console.ReadLine()   End Sub End Module 

This Visual Basic .NET program simply writes the text Hello, world! to the output window and waits for the user to hit the Return key. It declares a module, HelloWorld , that contains a single method, Main , that is run when the program executes. The Main method calls a system-defined method, WriteLine , on the System.Console class. The WriteLine method takes a string of characters and writes that string to the output window. Then the system-defined method ReadLine on the System.Console class is called. This method waits for the user to enter a string of characters and hit the Return key. The ReadLine call ensures that the output window does not immediately disappear.

Although compiling, executing, and debugging a Visual Basic .NET program is not discussed in detail in this book, a few helpful pointers can be discussed. If a machine has Visual Basic .NET installed as part of Visual Studio .NET, the following steps will compile and run the program.

  1. Start Visual Studio .NET.

  2. Create a new Visual Basic .NET Console Application project.

  3. Replace the code in the file Module1.vb with the previous code.

  4. Run the program by hitting the F5 key.

Alternatively, if a machine has only the .NET Framework installed, the following steps will compile and run the program.

  1. Use a text editor such as Notepad to create a new file named HelloWorld.vb , and type in the previous code.

  2. Find the Visual Basic .NET compiler, vbc.exe , provided by the .NET Framework.

  3. Run the Visual Basic .NET compiler on the source file you created, by typing vbc.exe HelloWorld.vb at a command prompt.

  4. Run the resulting program, HelloWorld.exe , by typing HelloWorld at a command prompt.

Running the Visual Basic .NET compiler causes the source code to be compiled from text into an assembly. An assembly is a file with an EXE or DLL extension that the .NET Framework can load and run. An assembly has a name (in this case, HelloWorld ) that distinguishes it from other assemblies and allows the .NET Framework to identify which assemblies need to be loaded to run a particular program. Inside an assembly are two things created by the compiler intermediate language instructions ( IL ) and metadata . IL is a machine language that the .NET Framework understands and can execute. Metadata is extra information about the program above and beyond what is stored in the IL. Metadata is used by the .NET Framework to ensure that the IL can be executed correctly and securely, and is also used by the .NET Framework Reflection APIs. You can learn more about the internals of the .NET Framework in the book Programming in the .NET Environment , by Damien Watkins, Mark Hammond, and Brad Abrams (Addison-Wesley, 2003).

 < Day Day Up > 

The Visual Basic .NET Programming Language
The Visual Basic .NET Programming Language
ISBN: 0321169514
EAN: 2147483647
Year: 2004
Pages: 173
Authors: Paul Vick

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net