Bug with SelLength? (Excel 2000)
Greetings,
In order to learn how to use VBScript's regular expression object, I wrote an Excel program that has a user form with several textboxes. You enter text in one, and a regEx in another, and (optionally) a replacement expression in a third then press a command button which will find matches, and hightlight them. It works (almost) perfectly. The problem is when I use multiline mode and try to match an expression that spans several lines. For example, if I enter This is (a test) I hope it works and try it against the regex \([\s\S]*\), it highlights (a test), as expected, but if I type This is ( a t e s t ) I hope it works with the same regEx, much of "I hope" is highlighted as well. It seems that SelLength is ignoring \n or \r or both. At the very least, this is somewhat undocumented behavior. By the way, the offending code snippet is Sub Highlight(myMatch As Match) Dim i As Integer, n As Integer i = myMatch.FirstIndex n = myMatch.Length tbText.SetFocus tbText.SelStart = i tbText.SelLength = n End Sub I guess I'll have to write a more complicated sub which starts at SelStart and steps through the characters one at a time using Mid and counting the number of line breaks so I can adjust SelLength appropriately, unless there is a simple work-around I am overlooking. -John Coleman |
All times are GMT +1. The time now is 05:10 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com