The User Form code module

PC Repair Tools

Advanced Registry Cleaner PC Diagnosis and Repair

Get Instant Access

All the real work is done by VBA code contained in the code module for UserForm1 . Here, I briefly describe each of the procedures in this module. The code is too lengthy to list here, but you can view it by opening the ® text tools.xlam file on the companion CD-ROM.

THE USERFORM_INITIALIZE PROCEDURE IN THE USERFORM1 CODE MODULE

This procedure is executed before the UserForm is displayed. It sizes the UserForm and retrieves (from the Windows Registry) the previously selected values for the controls. It also adds the list items to the ComboBox (named ComboBoxOperation ) that determines which operation will be performed. These items are:

■ Remove by position

■ Remove spaces

■ Delete characters

THE COMBOBOXOPERATION_CHANGE PROCEDURE IN THE USERFORM1 CODE MODULE

This procedure is executed whenever the user selects an item in the ComboBoxOperation . It does the work of displaying or hiding the other controls. For example, if the user selects the Change Case option, the code unhides the second ComboBox control (named ComboProcl ) and fills it with the following choices:

■ Sentence case

THE APPLYBUTTON_CLICK PROCEDURE IN THE USERFORM1 CODE MODULE

This procedure is executed when the Apply button is clicked. It does some error checking to ensure that a range is selected and then calls the CreateWorkRange function to make sure empty cells are not included in the cells to be processed. See the upcoming section, "Making the Text Tools utility efficient ."

The ApplyButton_Click procedure also calls the SaveForUndo procedure, which saves the current data in case the user needs to undo the operation. See "Implementing Undo ," later in this chapter.

The procedure then uses a Select Case construct to call the appropriate procedure to perform the operation. It calls one of the following Sub procedures:

■ ChangeCase

■ RemoveText

■ RemoveSpaces

■ RemoveCharacters

Some of these procedures make calls to function procedures. For example, the ChangeCase procedure might call the ToggleCase or SentenceCase procedures.

THE CLOSEBUTTON_CLICK PROCEDURE IN THE USERFORM1 CODE MODULE

This procedure is executed when the Close button is clicked. It saves the current control settings to the Windows Registry and then unloads the UserForm.

THE HELPBUTTON_CLICK PROCEDURE IN THE USERFORM1 CODE MODULE

This procedure is executed when the Help button is clicked. It simply displays the Help file (which is a standard compiled HTML help file).

Was this article helpful?

0 0

Post a comment