Results 1 to 4 of 4

Thread: RichTxtBox and Line Number

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    3

    RichTxtBox and Line Number

    I am writing a program that is making some manipulation with RichTextBox.

    I need to be able to capture a few information such as total number of lines in the RichTextBox, the current line (line with cursor).

    Any idea how to do it? Is it possible with RichTextBox or is there something else I can try?

    Thanks in advance.

  2. #2
    Yash_Kumar
    Guest
    Insert these 2 procedires in your code.

    Code:
    Public Function NumberOfLines(TextBox As RichTextBox) As Integer
    Dim sLines() As String
    
    sLines() = Split(TextBox.Text, vbCrLf)
    NumberOfLines = UBound(sLines) + 1
    End Function
    
    
    Public Function CurrentLine(TextBox As RichTextBox) As Integer
    Dim sCopy As String
    Dim sLines() As String
    Dim intCon As Integer
    
    sCopy = TextBox.Text
    sCopy = Mid(sCopy, 1, TextBox.SelStart) & "{VBROCKS}" & Mid(sCopy, TextBox.SelStart + 1)
    
    sLines() = Split(sCopy, vbCrLf)
    For intCon = 0 To UBound(sLines())
        If InStr(1, sLines(intCon), "{VBROCKS}") Then
            CurrentLine = intCon + 1
            Exit For
        End If
    Next
    End Function
    Now to determine the number of lines in the rich text box, u could call it like this
    Code:
    Msgbox NumberOfLines(MyRTFBox)
    To determine the current line
    Code:
    Msgbox CurrentLine(MyRTFBox)

  3. #3
    Hyperactive Member abhid's Avatar
    Join Date
    Nov 2001
    Location
    3rd rock from the sun
    Posts
    467

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    3
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width