-
Hi Everybody!
Does anyone know how to add text to a text box and when it reaches the bottom of the text box it automatically scrolls to the active line.
I have an application that imports numerous text files.
It adds a line in a text box to show what it has imported from each text file.
Your mission if you chose to accept:
If there are a lot to import and the text reaches the bottom of the text box it disappears. I want the text box to scroll down so the current line is allways in view.
Thanks in advance.
-
You could base your code on this sort of thing...
Code:
Private Sub Command1_Click()
Text1 = Text1 & Now() & vbCrLf
Text1.SelStart = GetLastVBCRLF(Text1)
End Sub
Private Function GetLastVBCRLF(strIN As String) As Long
Dim i As Long
Dim char As String
For i = Len(strIN) To 1 Step -1
char = Mid(strIN, i, 2)
If char = vbCrLf Then
Exit For
End If
Next i
GetLastVBCRLF = i
End Function
-
My Answer
Gazza,
Try this:
Code:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) _
As Long
Public Const EM_GETLINECOUNT = &HBA
Public Const EM_LINESCROLL = &HB6
Private Sub Text1_Change()
Dim lCount&, lRes&
lCount = SendMessage(ByVal Text1.hwnd, ByVal EM_GETLINECOUNT, 0, 0)
If lCount >= 10 Then ' or any value you like
lRes = SendMessage(ByVal Text1.hwnd, ByVal EM_LINESCROLL, 0, 1)
End If
End Sub