Adding Features to the Word Processor

One of the advantages of Object Oriented Programming is that we can work on each part of the program separately. We have created the complete interface to the word processor and, over the next few week, will add features.

The New Menu

The new menu must check to see if the file in the text box is saved. If it is, the text box is cleared. If not, the user must be asked if they would like to save their work first.

Suppose that we had a Boolean variable called Saved that is originally set to True (meaning that it is true that there is no work to be saved). It can be changed to False when something is typed in the text box. So--

In General Declarations

Private Saved As Boolean

In Form_Load

Saved = True 

In txtWord_Change( )

Saved = False 'this signals we need to save

In mnuNew

if (Saved) Then

  txtWord.Text = "" 'nothing between the quotes

Else

   mnuSave_Click 'Save the file
  txtWord.Text = ""  'then clear the text box

End If

In mnuSave

reset Save to True

The Exit Menu

The exit menu uses the familiar UnLoad method. It must use the same logic as the New menu to make sure the user has saved their work.

The Time/Date Menu

Both Time and Date are built in Visual Basic function. The Time function returns, as you might guess returns the system time and the Date function the system date. Thus:

MsgBox Time

Produces:

while

MsgBox Date

Produces

The SelText property of text boxes indicates the text "selected" by the user (text is selected by dragging the text with the mouse). If no text is selected, the Len(txtWord.SelText = 0). 

To produce the needed string, use the Str( ) function to convert everything to strings and the ampersand ( & ) to concatenate the results. Make the SelText property be equal to the produce string!

txtWord.SelText = Str(Time) & " " & Str(Date) + " "

The Select All Menu

Another property of text boxes is the SelStart property. It indicates the position of the cursor in the text boxes (in #'s of characters. To select all, 

set the SelStart property of txtWord to 0
set the SelLength property of txtWord to the length of the text in the text box

The About Menu

Use a message box to display an "About" box.


To create separate lines in the message, you can use the vbCr (Carriage Return) function in Visual Basic. Thus:

MsgBox "Hello" & vbCr & "My Name is Tom", vbExclamation, "Hello Message"

Produce