In this program, we're going to start a new example: the About Visual Basic Signature Block. Our first attempt will get the job done, but it has a few serious design flaws. You saw that the Hello World example in part 3, where we used a VB.NET module, had problems that were corrected in part 5 by creating a class and using more correct OOP design. You seldom do things the best way in your first attempt and learning what works and what doesn't is a big part of programming.
While we're writing this code, we will learn about these new VB.NET elements:
Structures - Compound data types that you create to organize information in your program
Secondary Forms - Using a different Windows form
Functions - Like subroutines, but they return values differently
Intrinsic Visual Basic Constants - Handy values that are always there for you to use
Short circuit operators - Syntax borrowed from the C language
Class Properties and Methods - the "crown jewels" of OOP
We won't use any external files in this program, a design choice that you'll see creates problems.
The Signature Block Program Requirements
The use of UML and two of the many UML diagrams (a Use Case and a State Diagram) were introduced in page 4 of part 3 of the tutorial. UML is a great tool for describing requirements and making sure that a system is designed well before starting on the code. In the example below, I haven't included a UML specification for the system mainly because this is a course in programming rather than analysis and design. The example goes through several modifications in the tutorial (actually, to illustrate different programming topics), but if you want to write the program right the first time, a thorough analysis using UML is the way to do it.
And if you do want to see more UML analysis of the Signature Block program, I've written a separate article that covers that, and some additional information about UML itself. The article is Interpreting the UML Modeling Language for Programmers.
When I write email messages, my email program automatically adds a signature block to messages. I find that the block that is automatically added is often not quite what I want, however. On some messages, I might want to make sure that my phone number is included in the block. (When I'm trying to get a new business client, for example.) But in others, I want to leave it out.
Updating the signature block through the email client is too much trouble and I forget to do it before hitting the "Send" key. What I need is a quick little program that will just display a block for me to "copy and paste" just before I send my message. That way, I'll be sure to get what I want.
So here are my initial requirements:
Use Cases
- Hold Personal Information
address
SSN
phone
email address
- Select Fields for Output
- Display Signature Block
The instructions for coding the Signature Block program start on the next page. I'm not going to add the unnecessary detail about how each component should be named. The code is available for download at the end and you can see what I did there. I'm just going to cover the main points. I think it will be easier to understand that way.
To get started, select New Project... under the File menu and chose Windows Forms Application in VB Express. Add two Button components and a TextBox component. The program starts with a main form named SigBlockForm. The code in that form is shown below. In fine OOP style, the code is simplicity itself:
(Parameters for Sub statements are not completely shown to keep lines short.)
Public Class SigBlockForm
Dim mySigBlock As New SigBlock
Private Sub DisplayBlock_Click(ByVal ...
SigBlockBox.Text = mySigBlock.Lines
End Sub
Private Sub SelectFields_Click(ByVal ...
SigFieldDisplay.Show()
End Sub
End Class
In fact, there are only three lines of code that you have to enter yourself:
Dim mySigBlock As New SigBlock
SigBlockBox.Text = mySigBlock.Lines
SigFieldDisplay.Show()
The rest are filled in by VB.NET. Double-click the button components to trigger the default code.
The first statement you code declares a new SigBlock object. This is the Class where most of the real work is done. Notice, however, that it's declared outside the subroutines. This gives it module level scope. That means that the SigBlock object will exist as long as the form itself does. Since we "save" information in the object while the program is running, that's necessary.
But VB.NET should be telling you that you have errors because "Type SigBlock is not defined". That's because we haven't created the class for this object yet. We'll do that on the next page.

