Someone asked once if it would be possible to limit the length of each line in a text box to 10 characters. This is the code I came up with:

VB Code:
  1. Option Explicit
  2.  
  3. 'API Declarations:
  4. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
  5.   (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
  6.   lParam As Any) As Long
  7.  
  8. 'Constant Delcarations
  9. Private Const EM_LINEINDEX = &HBB
  10. Private Const EM_LINELENGTH = &HC1
  11.  
  12. Private Sub Text1_KeyPress(KeyAscii As Integer)
  13. Dim lLen As Long
  14.  
  15.   'Get the length of the current line:
  16.   lLen = SendMessage(Text1.hwnd, EM_LINELENGTH, EM_LINEINDEX, 0&)
  17.  
  18.   'If length is 10, don't allow more characters:
  19.   If lLen = 10 And KeyAscii <> vbKeyReturn And KeyAscii <> vbKeyBack Then
  20.       KeyAscii = 0
  21.   End If
  22.  
  23. End Sub