Computer History - Herong's Notes - Version 3.11, by Dr. Herong Yang
HelloCLR.vb - Sample Application in VB
This section provides a tutorial example on compiling a sample program written in VB (Visual Basic) and executing it on the CLR (Common Language Runtime) of the .NET Framework.
New let's try to compile a simple application written in VB (Visual Basic) into a bytecode, so it can be executed by the CLR (Common Language Runtime) of the .NET Framework.
1. Enter the following source code in Notepad and save it file called, HelloCLR.vb:
' HelloCLR.vb ' Copyright (c) 2012 by Dr. Herong Yang, herongyang.com Imports System Public Module HelloCLR Sub Main() Console.WriteLine ("Hello VB CLR " _ & Environment.Version.ToString() & "!") End Sub End Module
2. Compile the source code stored in HelloCLR.vb using the .NET Framework 4 VB compiler in command window:
C:\herong>\windows\Microsoft.NET\Framework\v4.0.30319\vbc HelloCLR.vb Microsoft (R) Visual Basic Compiler version 10.0.30319.1 Copyright (c) Microsoft Corporation. All rights reserved. C:\herong>dir HelloCLR.* 225 HelloCLR.cs 6,656 HelloCLR.exe 234 HelloCLR.vb
The output of the "vbc" command is the bytecode of the program in Intermediate Language stored in file, HelloCLR.exe, in the PE (Portable Executable) format.
3. When HelloCLR.exe is entered from a command line, Windows will invoke .NET CLR (Command Language Runtime) to perform the execution step:
C:\herong>HelloCLR.exe Hello VB CLR 4.0.30319.239!
The CLR version number returned in the output shows that the program is executed in the .NET CLR virtual machine.
Last update: 2012.
Table of Contents