Turpis
Programmer
- Apr 16, 2002
- 151
I am building a program that provides an interface for editing CNC program files here at the shop. I thought it might be nice to point out certain machine codes in different colors for ease of coding. I wrote some test code to do this and though it works, I find myself wondering if there is a more efficient way of going about this.
Anybody have a better or different way to do this?
Charles
Quality Assurance/Developer
Code:
Private Sub btnBlueSelection_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBlueSelection.Click
Dim iRet As Integer = Me.rtbMain.SelectionStart
Dim i As Integer = 0
Dim j As Integer = 0
Dim iCont As Integer = 0
Dim myStr As String
Dim iFound() As Integer
[COLOR=green]'---Start from the beginning of text[/color]
Me.rtbMain.Select(0, 0)
[COLOR=green]'---Get the search string[/color]
myStr = InputBox("Input text string", "Find")
[COLOR=green]'---Find all the occurrences[/color]
Do
ReDim Preserve iFound(i)
iFound(i) = Me.rtbMain.Find(myStr, iCont, RichTextBoxFinds.WholeWord)
iCont = Me.rtbMain.SelectionStart + Len(myStr)
i += 1
Loop Until iCont > Len(Me.rtbMain.Text) Or Me.rtbMain.Find(myStr, iCont, RichTextBoxFinds.WholeWord) = -1
[COLOR=green]'---Change all found words[/color]
For j = 0 To iFound.Length - 1
Me.rtbMain.Select(iFound(j), Len(myStr))
Me.rtbMain.SelectionColor = Color.Blue
Next
[COLOR=green]'---Return focus to the box and cursor to[/color]
[COLOR=green]'---original position[/color]
Me.rtbMain.Focus()
Me.rtbMain.Select(iRet, 0)
End Sub
Anybody have a better or different way to do this?
Charles
Quality Assurance/Developer