PDA

Click to See Complete Forum and Search --> : Line Counter


vbNeo
Oct 8th, 2003, 10:52 AM
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:

'Declaring Sendmessage API
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
Private Const EM_GETLINECOUNT = &HBA
'Declaring oldline
Public Oldline As Integer

Private Sub Form_Load()
'Setting a default value for the RTB(Could do a _Change here instead)
txtLinecounter.Text = "1"
End Sub

Private Sub txtMain_Change()
Dim iLines As Long
Dim i As Integer
iLines = SendMessage(txtMain.hwnd, EM_GETLINECOUNT, 0, 0)
If Not iLines = Oldline Then
txtLinecounter.Text = ""
For i = 1 To iLines
txtLinecounter.Text = txtLinecounter.Text & i & vbCrLf
Next
txtLinecounter.SelStart = InStr(1, Liner, iLines - 1)
Oldline = iLines
Else
Oldline = iLines
End If
End Sub



Hope you like it, I remember having a lot trouble making this when i started doing VB(This one took 10 mins ;))

shaunyboy
Oct 27th, 2003, 09:12 AM
thanks for sharing, i was looking for something like this.

vbNeo
Oct 27th, 2003, 09:20 AM
No problem!

You might have some problems when wanting the boxes to scroll at the same time - i'm working on a way to fix this.

Cheers!