VB Replace Command Using Verify Can Incorrectly Repeat Replace

ID Number: Q73271

1.00

WINDOWS

buglist1.00

Summary:

This article discusses a problem with the Verify option of the Code

menu's Replace command in the Microsoft Visual Basic version 1.0

editor. If the search string is a subset of the replacement string,

and if the Visual Basic syntax parser automatically inserts a space in

the replacement string, then the Replace command with Verify

incorrectly repeats the Replace on text that was part of the

replacement string itself.

Microsoft has confirmed this to be a problem in Microsoft Visual Basic

version 1.0 programming system for Windows. Microsoft is researching

this problem and will post new information here as it becomes

available.

To work around the problem, you can manually put space that would be

inserted by the syntax parser in the replacement string (as described

below). The problem does not occur with the Replace All option.

More Information:

Steps to Reproduce Problem

--------------------------

1. Start Visual Basic (or select New Project from Visual Basic's File

menu).

2. From the Project1 window, double-click GLOBAL.BAS. This displays the

Global module window. (Note that this Replace problem can occur in

any code window.)

3. In the Global module window, enter the following code:

Global A(2)

[Or enter Dim A(2) in the code window of any non-Global module.]

4. Now choose the Replace command from the Code menu.

5. The Replace window contains two text boxes named "Find What:" and

"Replace With:". In the Find What text box, enter a ")" and then

tab to the Replace With text box and enter ",2)".

6. Choose the Verify command button.

7. The Verify window prompts you with "Replace Selected Text" [Yes] or

[No]. If you choose the Yes command button, the replacement

occurs correctly. The problem doesn't occur until you choose the

Yes command button for a second time (and third, and so on), which

will incorrectly add another string of text at the same location.

The problem is caused by the space that the Visual Basic parser

automatically inserts after the comma. This causes Visual Basic to

effectively start the next search one character too early, causing the

search to find the ")" that was just inserted. The problem can be

avoided by changing the Replace string to ", 2)" (with a space after

the comma).

You can also avoid the problem by choosing the "Replace All" command

button instead of the Verify command button (mentioned in step 6

above). This correctly does the Replace and displays the "Search

complete" window.

You can also avoid the problem by selecting the No command button the

second time the Verify window is displayed (in step 7) (and then

choose the OK command button when the "Search complete" window

displays).

Additional reference words: 1.00