Re: column count in VB6
From: Rick Rothstein (rickNOSPAMnews_at_NOSPAMcomcast.net)
Date: 11/24/04
- Next message: U-CDK_CHARLES\\Charles: "Form_Keypress event not happening?"
- Previous message: Jan Hyde: "Re: How to sign CABs,OCXs and DLLs?"
- In reply to: mikegyver: "Re: column count in VB6"
- Next in thread: mikegyver: "Re: column count in VB6"
- Reply: mikegyver: "Re: column count in VB6"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 24 Nov 2004 11:05:46 -0500
> Not sure If I'll address the question correctly, but
.getcurrentcolumnnumber
> is supposed to return me the current, I guess current Character count
on that
> line.
> I am using rich text box, but I guess it's referred to as
"uctmyrichtextbox".
>
> I really don't care what kinds of text box i'm using, all I care for
is the
> ability to have it give me the current character count that my curser
is at.
> The .getcurrentcolumnnumber does that, but stops after I go off the
left side
> of the page.
>From a previous post of mine (which I think addresses your question)...
Rick - MVP
The following, written for a normal TextBox, will also works with a
RichTextBox if the references are changed appropriately (TextBox to
RichTextBox).
Paste this code in the (General)(Declarations) section of your Form for
single form use; or place it into a BAS Module (Project/AddModule from
VB menu bar) for project wide scope:
Private Declare Function SendMessageLong Lib _
"user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Const EM_LINEFROMCHAR = &HC9
Const EM_LINEINDEX = &HBB
Function CursorLine(TextBoxIn As TextBox) As Long
CursorLine = SendMessageLong(TextBoxIn.hwnd, _
EM_LINEFROMCHAR, -1, 0) + 1
End Function
Function CursorColumn(TextBoxIn As TextBox) As Integer
CursorColumn = TextBoxIn.SelStart - SendMessageLong( _
TextBoxIn.hwnd, EM_LINEINDEX, -1, 0)
End Function
You only asked for the cursor line, but I've included a function that
also gives the column that the cursor is in. The CursorLine function
returns the line number counting the first line as Line #1. The
CursorColumn function returns the number of characters that exist to the
left of the cursor. Simply pass the TextBox in as an argument to either
function; for example
Private Sub Text1_Click()
MsgBox "The cursor is on Line #" & CursorLine(Text1) & _
" at Column #" & CursorColumn(Text1)
End Sub
- Next message: U-CDK_CHARLES\\Charles: "Form_Keypress event not happening?"
- Previous message: Jan Hyde: "Re: How to sign CABs,OCXs and DLLs?"
- In reply to: mikegyver: "Re: column count in VB6"
- Next in thread: mikegyver: "Re: column count in VB6"
- Reply: mikegyver: "Re: column count in VB6"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|