March 31, 2001

TextBoxGetLine – Return a single line in a multiline TextBox control

Private Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal _ hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _ lParam As Any) As LongConst EM_LINEINDEX = &HBBConst EM_LINELENGTH = &HC1′ Return the specified line in a multiline TextBox control.Function TextBoxGetLine(tb As TextBox, ByVal lineNum As Long) As

TextBoxGetLines – Get an array with individual lines in a TextBox control

Private Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal _ hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _ lParam As Any) As LongConst EM_FMTLINES = &HC8′ Return an array with all the lines in the control.’ If the second optional argument is True, the hard CR-LFs

TextBoxScroll – Programmatically scroll a multi-line TextBox control

Private Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal _ hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _ lParam As Any) As LongConst EM_LINESCROLL = &HB6′ Scroll the contents of the control.” Positive values scroll left and up, negative values scroll right and down.’ IMPORTANT: you

Ensure that a TextBox caret is visible

Setting a multiline TextBox’s SelStart property doesn’t ensure that the insertion point (the caret) is visible. You can achieve this by sending the control an appropriate message: Private Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal _ hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _ lParam

TextBoxGetLineColumn – Get caret position in a multiline TextBox control

Private Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal _ hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _ lParam As Any) As LongConst EM_LINEFROMCHAR = &HC9Const EM_LINEINDEX = &HBB’ Get the line/column coordinates of a given character (both are zero-based).’ If charIndex is negative, it returns

Set tab stop positions for a multiline TextBox control

By default, multiline TextBox controls insert a tab stop position every 8 characters; in other words, if you press the Ctrl+Tab key while the focus is inside a multiline TextBox control, the caret advances to position 8,16,24, etc. (If the TextBox is the only control on the form that can