Results 1 to 3 of 3

Thread: Line Counter

Threaded View

  1. #1
    Frenzied Member vbNeo's Avatar
    Join Date
    May 02
    Location
    Jutland, Denmark
    Posts
    1,994

    Line Counter

    This counts the lines in one RTB and displays it in another

    Place 2 rtb's on your form, call one of them txtLinecounter, and the other one txtMain

    Then insert this code:
    VB Code:
    1. 'Declaring Sendmessage API
    2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    3. Private Const EM_GETLINECOUNT = &HBA
    4. 'Declaring oldline
    5. Public Oldline As Integer
    6.  
    7. Private Sub Form_Load()
    8. 'Setting a default value for the RTB(Could do a _Change here instead)
    9. txtLinecounter.Text = "1"
    10. End Sub
    11.  
    12. Private Sub txtMain_Change()
    13. Dim iLines As Long
    14. Dim i As Integer
    15. iLines = SendMessage(txtMain.hwnd, EM_GETLINECOUNT, 0, 0)
    16. If Not iLines = Oldline Then
    17. txtLinecounter.Text = ""
    18. For i = 1 To iLines
    19. txtLinecounter.Text = txtLinecounter.Text & i & vbCrLf
    20. Next
    21. txtLinecounter.SelStart = InStr(1, Liner, iLines - 1)
    22. Oldline = iLines
    23. Else
    24. Oldline = iLines
    25. End If
    26. End Sub

    Hope you like it, I remember having a lot trouble making this when i started doing VB(This one took 10 mins )
    Last edited by vbNeo; Oct 8th, 2003 at 12:54 PM.
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

Posting Permissions

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