victoryhighway2
Programmer
Hello Group,
I'm trying to use the Microsoft Rich Text Box control as the basis of a basic text editor. I'm also using a Status Bar control in the form and I'd like to provide the line and character position of the cursor in the status bar. Getting the (absolute) character position is easy with the SelStart property of the RichTextBox control. However, I've been having difficulty trying to break that down into the line and the relative character position. This is the code that I've written so far:
So far, I haven't been able to figure this out.
Could anyone give me a hand with it?
I appreciate in advance and help you can offer.
Regards,
Geoffrey
I'm trying to use the Microsoft Rich Text Box control as the basis of a basic text editor. I'm also using a Status Bar control in the form and I'd like to provide the line and character position of the cursor in the status bar. Getting the (absolute) character position is easy with the SelStart property of the RichTextBox control. However, I've been having difficulty trying to break that down into the line and the relative character position. This is the code that I've written so far:
Code:
Private Sub GetPosition()
Dim strCAMS() As String
Dim intCount As Integer
Dim lngCount As Integer
Dim lngLine As Long
Dim lngChar As Long
Dim strTest As String
Dim intTest As Integer
Dim strCharTest As String
strCAMS = Split(Me.txtAddCams.Text, vbCrLf)
intCount = 0
lngCount = 0
For intCount = LBound(strCAMS) To UBound(strCAMS)
If intCount = LBound(strCAMS) Then
intLineStart = 1
End If
intLineEnd = intLineStart + Len(strCAMS(intCount))
lngCount = lngCount + Len(strCAMS(intCount)) + 2
If (Me.txtAddCams.SelStart >= lngCount) And (Me.txtAddCams.SelStart <= lngCount) Then
strTest = Mid(Me.txtAddCams.Text, lngCount, Len(strCAMS(intCount)))
For intTest = 1 To Len(strTest)
strCharTest = Mid(strTest, intTest, 1)
If Asc(strCharTest) < &H20 And Asc(strCharTest) > &H7F Then
lngCount = lngCount + 1
End If
Next intTest
If strCAMS(intCount) = strTest Then
lngLine = intCount + 1
lngChar = (Me.txtAddCams.SelStart - lngCount) + 1
Me.sbStatusBar.Panels(Panels.Line).Text = "Line: " & lngLine
Me.sbStatusBar.Panels(Panels.Char).Text = "Char: " & lngChar
End If
Exit For
End If
Next intCount
End Sub
So far, I haven't been able to figure this out.
Could anyone give me a hand with it?
I appreciate in advance and help you can offer.
Regards,
Geoffrey