On Wed, 23 Jun 2004 23:50:55 -0700, "Newsgroup" <pm*@swannack.n et>
wrote:
I have a multiline textbox with 10 lines of text in it. I want to search
Line by Line for the word" [Option]". How do I process one line in a text
box at a time? I DON'T want to just search the whole textbox for my word,
because when I find it, I want to stop the cursor there until the user
decides to continue to find the next instance.
MY QUESTION IS: How can I search for text line by line in a textbox?
Option Explicit
' Add one Textbox
' Set it to MultiLine
Private Declare Function SendMessage Lib _
"user32" Alias "SendMessag eA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Function SendMessageStr Lib _
"user32" Alias "SendMessag eA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String) As Long
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_GETLINE = &HC4
Private Const EM_LINELENGTH = &HC1
Private Const EM_LINEINDEX = &HBB
Private Sub Command1_Click( )
Dim Lines&, S$, P&, L&
Const LINE_NO = 2
' --- Count the Lines
Lines& = SendMessage(Tex t1.hwnd, _
EM_GETLINECOUNT , _
0, _
0)
Me.Print Lines
' Note: If Text1.Text = "" then 1 is returned
' --- Now get position of start of 2nd line
' this is zero based
P& = SendMessage(Tex t1.hwnd, _
EM_LINEINDEX, _
LINE_NO - 1, _
0)
Me.Print "Line 2 Starts at:"; P
' --- Now Get its Length
L& = SendMessage(Tex t1.hwnd, _
EM_LINELENGTH, _
P, _
0)
Me.Print "Length of Line 2 is:"; L
' --- Now Get Line 2
S$ = Space$(L)
L& = SendMessageStr( Text1.hwnd, _
EM_GETLINE, _
LINE_NO - 1, _
S)
Me.Print S$
' --- And to prove it
Me.Print Mid$(Text1.Text , P + 1, L)
End Sub