Word Processor .01
Step by Step

As promised in class, we will work through the Word Processing program step by step. The first step, writing the interface is up to you. For the first part of the lesson, we will program the font size scroll bar, the Exit button, and the Clear button.

This lesson assumes that you have designed the interface and that it looks like this:

The objects (from upper right to lower left are:

bullet

frmWord

bullet

txtWord

bullet

fraFontName
bullet

optSansSerif

bullet

optArial

bullet

optCenturySchoolbook

bullet

fraFontStyle
bullet

chkBold

bullet

chkItalic

bullet

chkUnderline

bullet

lblFontSizeLabel

bullet

lblFontSize

bullet

hspFontSize

bullet

cmdClear

bullet

cmdEnd

Word Processor .01 Step by Step

bullet

Horizontal Scroll Bar

bullet

Clear Button

bullet

Exit Button

bullet

Radio (Option Buttons)

bullet

Check Boxes

The Horizontal Scroll Bar

We want the user to be able to select a font size between 6 and 22 points. The initial value should be 14 (half way between). We must always display the current font size in lblFontSize.

Set the following properties at design time:

hsbFontSize
bullet

value = 14

bullet

min = 6

bullet

max = 22

bullet

smallchange = 4

bullet

largechange = 4

You must also put the initial value of the scroll bar (14) in the label (lblFontSize.Caption)

lblFontSize

bullet

Caption = 14

bullet

Alignment = Center (looks prettier!)

The code behind the horizontal scroll bar does 2 things- first it changes the fontsize property of the text box (txtText) to the value of the horizontal scroll bar. Second, it changes the caption property of the label (lblFontSize) to the value of the horizontal scroll bar. The code goes in the Change event, which occurs whenever the value of the scroll bar changes. The psuedocode is:

 let the font size of the text box  =  the value of the scroll bar

let the caption property of the label = the value of the scroll bar

You should also be able to program the Clear button (Let the text property of the text box = nothing! (nothing = "") and the Exit button (Unload Me).

Test and debug your program. Type some text in the text box and move the scroll bar. The text should change size and the label should reflect the new size.

The Option (Radio) Buttons

The option buttons control the font that is displayed in the text window. Option buttons are used because only one font can be selected. Since. by definition, only one option button is selected, the code is straightforward. Just send the text box a message saying "Change your font name to ----"

txtWord.FontName = "MS Sans Serif"

A word of caution-- spelling counts! (You must have the name of the font exactly the same as the font name on the system. Simply click on the Font property of any object to see the possibilities!) The other two option buttons have similar code. Note that the event we are programming is called "click" just like a button!)

Also note that the default font for the text box is MS Sans Serif. Therefore, the Sans Serif option button should have its value property changed to True. This will make it the default button when you run the program.

The Check Boxes

The check boxes are used to allow the user to select from several font styles, namely bold, italics, and/or underline. Check boxes are used because the user may select any number of the choices (unlike radio buttons where you may select one and only one!) When you check a box that is "on" it turns "off" and visa versa. This means that your code must check to see if the box is being selected or "unselected." For example, for chkFontBold-

If (the fontbold property of the text box is True) Then

make it false

Else

make it try

in Visual Basic:

If (txtWord.FontBold = True) Then

txtWord.FontBold = False

Else

txtWord.FontBold = True

End If

The other check boxes work in a similar manner.