Designing Find and Replace Dialog Boxes

Because I like the design of Visual Basic’s Find and Replace dialog boxes, I used them as the model for XEditor’s dialog boxes (although I sometimes wish that the Find dialog box was modal instead of modeless).

The obvious design solution is to create both a Find form and a Replace form, on the premise that these are separate operations. But if you carefully study Figure 9-3 on the facing page, you’ll notice a lot of shared features. In fact, the Find dialog box morphs into the Replace dialog box with a simple mouse click. I’d argue that the most efficient way to implement them in Visual Basic is to create one form that can appear in Find or Replace format, depending on how you set the properties.

The trade-off here is code versus data. If you create two dialog boxes, you get two forms plus doubles of all the controls that appear in both. You also duplicate the code that handles common features. If you create one dialog box, you get only one form, one copy of each control, and one copy of all the code that handles the controls—although you need to add morphing code to hide unnecessary controls in the Find dialog box, to move controls around, to change button names, and so on.

As you can see in Figure 9-4, XEditor’s Find and Replace dialog boxes differ a little from those in Visual Basic. The framed Search options in the Visual Basic dialog boxes—which allow you to choose the current procedure, module, pro­ject, or selected text—don’t apply to a general text editor, so you can use that area for messages instead.

Figure 9-3. Visual Basic’s Find and Replace dialog boxes.

Figure 9-4. XEditor’s Find and Replace dialog boxes.

The Use Pattern Matching check box is also missing. Although the Visual Basic library has the power to help you provide pattern matching, it doesn’t make that power easily available. The Visual Basic Like operator supplies a powerful pattern-matching language for comparing strings, but you need an InStrLike for finding them. I’ve seen code that does clever hacks with the Like operator for kludge pattern searching, but I don’t have an extra chapter to explain something that works only part of the time. Maybe we’ll see the equivalent of InStrLike someday. Recognizing whole words is a much simpler problem.