Creating Classes

In this section you will create a simple Sentence class in a Word solution. As in Chapter 1, you will save the VSTO solutions that are described in this book in the Samples directory at the root of the C:\ drive.

1. Open Visual Studio 2005.

2. On the File menu, point to New and then click Project.

3. In the New Project dialog box, select Word Document in the Templates pane.

4. Name the solution SampleDocument, and set the location to C:\Samples.

5. In the Visual Studio Tools for Office Project Wizard, select Create a New Document, and then click OK.

6. In Solution Explorer, right-click the solution node, point to Add, and select New Item.

7. In the New Item dialog box, select Class, name the class Sentence.vb, and click Add.

Visual Studio creates the Sentence class and then opens the class file in code view.

8. Add the code in Listing 3.2 to the Sentence class.

Listing 3.2. Creating a property named Text for the Sentence class

Public Class Sentence

Private TextValue as String Property Text() As String Get

Return TextValue End Get

Set (ByVal value As String)

TextValue = value End Set End Property End Class

The variable TextValue is a private member variable. You can retrieve and set its value only by using the public Text property.

0 0

Post a comment