A few simple textbox functions
VB Code:
  1. Option Explicit
  2.  
  3. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
  4.                                                                         ByVal wMsg As Long, _
  5.                                                                         ByVal wParam As Long, _
  6.                                                                         lParam As Any) _
  7.                                                                         As Long
  8.  
  9. Private Const EM_GETLINECOUNT = &HBA
  10. Private Const EM_LINEFROMCHAR = &HC9
  11. Private Const EM_LINELENGTH = &HC1
  12.  
  13. Private Function GetLineCount(txt As TextBox) As Long
  14.     GetLineCount = SendMessage(txt.hwnd, EM_GETLINECOUNT, ByVal 0&, ByVal 0&)
  15. End Function
  16.  
  17. Private Function GetCurrentLine(txt As TextBox) As Long
  18.     GetCurrentLine = SendMessage(txt.hwnd, EM_LINEFROMCHAR, ByVal txt.SelStart, ByVal 0&) + 1
  19. End Function
  20.  
  21. Private Function GetLineLength(txt As TextBox, line As Long) As Long
  22.     GetLineLength = SendMessage(txt.hwnd, EM_LINELENGTH, ByVal line, ByVal 0&)
  23. End Function
  24.  
  25. Private Sub Command1_Click()
  26.  
  27.     MsgBox GetLineCount(Text1)
  28.     MsgBox GetCurrentLine(Text1)
  29.     MsgBox GetLineLength(Text1, GetCurrentLine(Text1))
  30.  
  31. End Sub