BUG: The Find method of the RichTextBox control searches text from the zero position when the Start parameter is equal to the length of the string (814318)
The information in this article applies to:
- Microsoft Visual Studio .NET (2003), Professional Edition
- Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2003), Academic Edition
- Microsoft Visual Studio .NET (2002), Professional Edition
- Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2002), Academic Edition
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# .NET (2003)
- Microsoft Visual C# .NET (2002)
SYMPTOMSWhen the Start parameter is equal to the length of the string, the Find method of the RichTextBox control does not raise an exception, even though the string
positional count starts with zero. For example, if the string is
"abcde", string position
zero indicates that the string starts from
"a". When the Start parameter is set to the string length, RichTextBox searches the string from the zero position, and then returns the
first instance position of the search string.CAUSEThis bug occurs because the Find method of the RichTextBox control does not handle the upper boundary condition (RichTextBox.Text.Length).RESOLUTIONBefore you run the Find method, determine if the Start parameter is greater than the length of the string. If the Start parameter is greater, raise an exception or else you call the Find method. To do this, use the following code: Visual Basic .NET Code ' Assign some value
RichTextBox1.Text = "abcde"
' Set start parameter as length of the string
Dim position As Integer
Dim startParam As Integer
startParam = 6
If startParam >= RichTextBox1.Text.Length Then
Throw New ArgumentException("'start' should be between 0 and 4.")
Else
position = RichTextBox1.Find("bc", startParam, RichTextBoxFinds.None)
End If
MsgBox(position) Visual C# .NET Code // Assign some value
RichTextBox1.Text = "abcde";
// Set start parameter as length of the string
int position;
int startParam;
startParam = 6;
if (startParam >= RichTextBox1.Text.Length)
{
throw new ArgumentException("'start' should be between 0 and 4.");
}
else
{
position = RichTextBox1.Find("bc", startParam, RichTextBoxFinds.None);
}
MessageBox.Show(position.ToString());
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
Modification Type: | Minor | Last Reviewed: | 2/3/2006 |
---|
Keywords: | kbvs2005swept kbvs2005doesnotapply kbvs2002sp1sweep kbBug kbRichEdit kbWindowsForms kbControl kbCtrl KB814318 kbAudDeveloper |
---|
|