Forum Discussion

davefarmercsi's avatar
davefarmercsi
New Contributor
15 years ago

Find/Replace not working correctly

Editing a script, I was using the Find/Replace function. I was trying to replace the string MainW with mainWindow. I didn't use the Replace All button (because I didn't want MainWin to become mainWindowin). I would use the Find Next button to find the next instance of MainW, visually verify that I wanted to do the replacement, then click the Replace button. The normal action would be for that instance of MainW to be replaced with mainWindow and the the next instance of MainW found. However, about 15% of the time, clicking the Replace button would do this: the replacement was made incorrectly (and unpredictably), the next instance of MainW was found, with the replacement already made to that instance. (That was my clue that the replacement was done incorrectly: I would be positioned on the next instance of MainW, but it was already changed to mainWindow.) The bad replacement was unpredictable: Sometimes it replaced MainW with nW; sometimes it deleted that and characters after it without inserting anything; etc.



If I undid the erroneous action and tried it again, I'd get the same bad results on that instance. So there must be a reason; it's not a random event. (I did not have Match Case or any of the other option checkboxes checked, in case that helps.)



This happened with multiple find/replace combinations, not just the one in my example. And the error is unpredictable: I've even seen it do multiple replacements from a single click of the Replace button. My only reliable solution is to use the Find to locate the instances and paste in the replacement myself. Major pain when there is supposed to be a simpler, standard way to do this.



Is this a known bug in the editor?

3 Replies


  • Hi Dave,





    We have tried to reproduce the problem, but failed.





    Could you please post the code from the script unit and specify in detail the steps to reproduce the problem?
  • Thanks.



    I have duplicated these exact steps four (out of four) times.



    I am searching for mainw and replacing it with mainWindow. No Find Options are checked. (See tc_find_replace_1.jpg.)



    Starting at the beginning of the attached script, I click Find Next. It finds MainW on line 24. I click Replace. MainW is correctly replaced and the next instance of mainw is found on line 328. However, the instance is not the MainW that I want to replace, so I click Find Next and advance to line 336. Again, this is not something I want to replace, so I click Find Next. At line 369, I do want to replace MainW, so I click Replace, which works correctly and takes me to line 427. I click Replace again, and MainW is changed to mainWindow, and I'm taken to the next instance at line 429. Clicking Replace there works fine, taking me to line 430. This is where it goes wrong.



    Notice that the next instance of mainw after line 430 is on line 444. (See tc_find_replace_2.jpg.) While positioned on MainW on line 430, I click Replace. MainW.activate on line 430 is changed to activate. The next instance of mainw on line 444 is highlighted, but MainW there has already been changed to mainWindow. (See tc_find_replace_3.jpg.)



    I have spent a lot of time cleaning up code after using the Replace All button before I realized that it didn't work correctly. Right now, I have to use the Find function and paste in the change manually.



    I am using version 7.52.678.7.



    Thanks for your help.