|
Adding Features to the Word ProcessorOne 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 MenuThe 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 End If In mnuSave reset Save to True
The Exit MenuThe 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 MenuBoth 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 TimeProduces:
while MsgBox DateProduces
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 MenuAnother 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
The About MenuUse a message box to display an "About" box.
MsgBox "Hello" & vbCr & "My Name is Tom", vbExclamation, "Hello Message" Produce
|