CodeItBetter Programming Another VB Programming Blog

How to goto the given line Number in Rich Text Box

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'Controls - How to goto the given line Number in Rich Text Box
Option Explicit
 
Public Const EM_LINEINDEX = &HBB
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
 
Public Sub GoToLineNo(rtf As RichTextBox)
    Dim LineNo As Integer, CharIndex As Integer
    Dim strLine As String
 
    strLine = Trim$(InputBox("Enter Line number:"))
    If Len(strLine) = 0 Then Exit Sub
    If IsNumeric(strLine) Then
        LineNo = CInt(strLine) - 1
        CharIndex = SendMessage(rtf.hWnd, EM_LINEINDEX, ByVal LineNo, ByVal CLng(0))
        rtf.SetFocus
        If CharIndex <> -1 Then
            rtf.SelStart = CharIndex
        End If
    Else
        MsgBox "Please input a line number", vbCritical
    End If
End Sub
Filed under: Controls Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.