Word Processor Version .01

The first version of our word processor will use a variety of Visual Basic controls to allow the user to set the font name (radio buttons), font style (check boxes), and font size (horizontal scroll bar).

The Horizontal Scroll Bar

The Horizontal Scroll Bar (as well as the Vertical Scroll Bar) allow the user to select an integer by sliding a scroll bar.

bullet

The range of integers the horizontal scroll bar can represent is set by the max and min properties.

bullet

The scroll bar does not have a caption property. In order to see the value of the scroll bar, you must use a label.

bullet

The value property specifies the initial value of the scroll bar.

bullet

The amount the scroll bar changes when click on an arrow is controlled by the smallchange property

bullet

The amount the scroll bar changes when click a the open area between the handle and the arrow is controlled by the largechange property

bullet

The Change event occurs whenever the value of the scroll bar changes.

Example

The following program allow the use to input a number between 1 and 100.

Design the Interface

Set the Properties

Scroll Bar  Name = hsbScroll1
Value = 50
smallchange = 1
largechange = 5
Label Name = lblValue
Caption = "50"
Alignment = Center

Write the Code

Private Sub hsbScrollBar1_Change()

lblValue.Caption = hsbScrollBar1.Value

End Sub

Option Boxes and Check Boxes

Option buttons (AKA Radio buttons) allow the user to choose from many choices. They must choose 1 and only 1 option. Choosing 1 "unchooses" the rest! Option buttons look like this:

Small Font
Big Font

Check boxes are used when the user may choose as many selections as they would like (including zero!). Here is what check boxes look like.

Font Bold
Font Underline

Write a program that uses option buttons to set a font size and check boxes to select font style.

Design the Interface

Set The Properties

lblTestFont

bullet Alignment = Center
bullet Caption = "Test Font Style"
bullet FontSize = 14

optSmallFont

bullet Caption = "Small Font"
bullet Value = "True"

chkBold

bullet Caption = "Bold"
bullet Value = "0- unchecked"

Write the Code

For the option button, the code is simple. If it is clicked, set the font to the small size. Since the control automatically is linked to the other option button, that's all you have to do.

Private Sub optSmallFont_Click()

lblTestFont.FontSize = 14

End Sub

The check boxes are a little more complex. Use and If..Then to determine the status. This type of control is called a switch in programming.

Private Sub chkBold_Click()

If chkBold.Value = 0 Then

lblTestFont.FontBold = False

Else

lblTestFont.FontBold = True

End If

End Sub

Now we can design the first version of our Word Processor.

Design the Form

 Select New Form from the File Menu and Design the form as below

Set the Properties  

Object

Name

Properties

Form

frmWord

BackColor = Make it blue
Caption  = "Word Processor .01"

Command Button

cmdClear

Caption =  "&Clear"

Command Button

cmdExit

Caption  =  "E&xit"

Text Box

txtFontSize

Alignment = Center

Scroll Bar

HSBFontSize

LargeChange =  4
Max = 22
Min =   6
SmallChange = 4
Value = 14

Check Box

chkItalics

 BackColor = Make it blue
Caption = “&Italics”

Check Box

chkUnderline

BackColor = Make it blue
Caption = “&Underline”

Check Box

chkBold

BackColor = Make it blue
Caption = "&Bold"

Option Button

optSchoolbook

BackColor = Make it blue
Caption = "Schoolbook"
FontName = "Century Schoolbook"
FontSize = 8.25

Option Button

optArial

BackColor = Make it blue
Caption =   "Arial"
FontName =   "Arial"
FontSize =   8.25

Option Button

optSansSerif

BackColor = Make it blue
Caption =   "Sans Serif"

Text Box

txtText

FontBold = False
MultiLine = True
ScrollBars = Vertical

Label

Label3

Alignment = Center
BackColor = Make it blue
Caption = "Font Size:"

Label

lblFontType

BackColor = Make it blue
Caption =   "Font Type:"

Label

lblFont

BackColor = Make it blue
Caption = "Select Font:"


Write the Code

For chkBold:

If chkBold is false Then

 set Font bold in text widow to False

 Else

   set Font bold in text widow to True

For chkItalics

   If chkItalics is false

   set Font Italic in text window to False

  Else

    set Font Italic in text window to True

For HSBFontSize

set text size caption to HSB’s Font size

set text.window font size to HSB Font size

For optArial

If its value is True Then

  txtText.FontName = "Arial"

For chkUnderline

If its underline value is  False Then

  set Font underline in text window to False

Else

set Font underline in text window to False

For optSansSerif

If its’ value is True

  set Font name to "MS Sans Serif"