Question about Text Boxes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Newsgroup

    #1

    Question about Text Boxes

    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?

    Thank You,
    Paul


  • J French

    #2
    Re: Question about Text Boxes

    On Wed, 23 Jun 2004 23:50:55 -0700, "Newsgroup" <pms@swannack.n et>
    wrote:
    [color=blue]
    >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?[/color]

    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

    Comment

    • Rick Rothstein

      #3
      Re: Question about Text Boxes

      > I have a multiline textbox with 10 lines of text in it. I want to
      search[color=blue]
      > Line by Line for the word" [Option]". How do I process one line in a[/color]
      text[color=blue]
      > box at a time? I DON'T want to just search the whole textbox for my[/color]
      word,[color=blue]
      > 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[/color]
      textbox?

      I'm not sure why you don't simply want to skip down through all the
      words you want to find. Put the following code in a CommandButton and
      load up your TextBox with text containing the word you want to find (in
      this case, " [Option]", with the leading space as shown). Now keep
      pressing the button and watch the TextBox.

      Rick - MVP

      Dim Position As Long
      Dim WordToFind As String
      WordToFind = " [Option]"
      With Text1
      If .SelLength Then .SelStart = .SelStart + .SelLength
      Position = InStr(.SelStart + 1, .Text, WordToFind)
      If Position Then
      .SelStart = Position - 1
      Else
      .SelStart = InStr(.Text, WordToFind) - 1
      End If
      .SelLength = Len(WordToFind)
      .SetFocus
      End With

      Comment

      Working...