O'Reilly logo

Object-Oriented Programming with Visual Basic .NET by J.P. Hamilton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.1. Creating and Compiling the Component

Example 2-1 contains the listing for our "Hello, world" component. It contains a single class named Hello with a single method named Write. Save the listing to a file named hello.vb. The rest of the chapter will use this listing as a foundation of discussion.

All Visual Basic source code should be saved to files with a .vb extension. One file can contain one class or several classes. How you organize the code is up to you.

Example 2-1. The "Hello, world" component
Option Strict On
   
Imports System
   
Namespace Greeting
   
Public Class Hello
    Public Sub Write(ByVal value As String)
        Console.WriteLine("Hello, {0}!", value)
    End Sub
End Class
   
End Namespace

The Visual Basic .NET command-line compiler is a program called vbc.exe that should be in your path once the .NET Framework is installed. All examples in this book assume that the example code exists in the root directory of your hard drive. This assumption is made to improve readability. If the code is not in your hard drive's root directory, you need to specify a fully qualified pathname to the compiled file or compile from the directory where the source code is located. With this in mind, you should be able to compile Example 2-1 to a dynamic link library (DLL) as follows:

C:\>vbc /t:library hello.vb

The /t: option is short for target, which can be one of the following values:

exe

A console ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required