| This demos using the API to retrieve the line count, line index and line length, to display the size of a document in a textbox.. BAS Module Code None. -------------------------------------------------------------------------------- Form Code Add the following code to the form. The demo shows calling the method from the textbox change event:: -------------------------------------------------------------------------------- Option Explicit 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 Private Const EM_LINEINDEX = &HBB Private Const EM_LINELENGTH = &HC1 Sub Text1_Change() Dim lineCount as Long Dim ChrsUpToLast As Long Dim DocumentSize As Long On Local Error Resume Next 'first obtain the number of lines in the textbox lineCount = SendMessage(Text1.hwnd, _ EM_GETLINECOUNT, _ 0&, _ ByVal 0&) 'Next, determine the number of characters up to the 'last line in the textbox ChrsUpToLast = SendMessage(Text1.hwnd, _ EM_LINEINDEX, _ lineCount - 1, _ ByVal 0&) If ChrsUpToLast = 0 Then DocumentSize = 0 ElseIf ChrsUpToLast < 65000 then DocumentSize = SendMessage(Text1.hwnd, _ EM_LINELENGTH, _ ChrsUpToLast, _ ByVal 0&) + ChrsUpToLast End If Label1.Caption = DocumentSize End Sub '--end block--' Comments The textbox passed to the SendMessage API must have its multiline property set to true at design time. The EM_GETLINECOUNT message does not pass additional parameters to the API in the wParam or lParam variables. These must be 0. With EM_LINEINDEX, the value of the wParam parameter specifies the zero-based line number. A value of -1 specifies the current line number (the line that contains the caret). lParam is not used an must be 0. With EM_LINELENGTH, the value of the wParam parameter specifies the character index of a character in the line whose length is to be retrieved. If this parameter is -1, the message returns the number of unselected characters on lines containing selected characters. lParam is not used an must be 0. The statement "ElseIf ChrsUpToLast <65000 Then" is for 32-bit VB .. vb4-16 and vb3 should use no more than 32000. |
How to Determine Textbox Document Size using the A |
Freelance ASP PHP web development | Web developer India Web development India| Prayagasoft - web designer India, Ecommerce developer india, Ecommerce design