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:
'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)




)
Reply With Quote