Results 1 to 6 of 6

Thread: Searching up through richtextbox (not down)

  1. #1

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Searching up through richtextbox (not down)

    I've been trying to figure this out lately by looping a richtextboxfinds code replacing the integer with a value -1 than the integer before it after the starting string in that code. But for some reason I can't get it to loop through my text upwards.

    It loops down through the text fine, however i'm not satisfied with that loop either, it seems a bit buggy.

    vb Code:
    1. Dim x As Integer
    2.         If searchdown.Checked Then
    3.             'We'll define fOption as the richtextbox finds option for searching the text
    4.             Dim fOption As RichTextBoxFinds = 0
    5.             If ckCaseSensitive.Checked Then fOption = fOption Or RichTextBoxFinds.MatchCase
    6.             If ckWholeWord.Checked Then fOption = fOption Or RichTextBoxFinds.WholeWord
    7.             x = Form1.RichTextBox1.Find(txtFind.Text, PlaceHolder, fOption)
    8.  
    9.             PlaceHolder = Form1.RichTextBox1.SelectionStart + 1
    10.  
    11.             If x < 0 Then
    12.                 If MessageBox.Show("There are no more occurances of the text " & txtFind.Text & vbCrLf & "or the text does not exist in the document. Would you like to start from the beginning of the document?", "Not found", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
    13.                     PlaceHolder = 0
    14.                     btnFindNext.PerformClick()
    15.                 End If
    16.             End If

    With using selection start -1 to get the integer to reduce in value it doesn't seem to want to use that placeholder to search upward through the text. And It wouldn't seem that the reverse code for richtextboxfinds would be appropriate for this either, i've tried using the value for it (16) in the code with a few different methods and nothing seemed to work for me.

    Anyone want to help me understand what i'm doing wrong here, or if there's anything I could do to better my downsearch/upwardsearch

    The down search seems to take 2 clicks on my button handler to actually change the selected text that it finds, and then I used the code for an upward search, it would search one more down upon pressing my "search up" button, before not doing anything after that on the next click. So i'd assume something is wrong with the down search function as well.
    Last edited by AceInfinity; May 27th, 2011 at 07:17 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Searching up through richtextbox (not down)

    try this:

    vb Code:
    1. Dim x As Integer
    2. 'We'll define fOption as the richtextbox finds option for searching the text
    3. Dim fOption As RichTextBoxFinds = 0
    4. fOption = fOption Or RichTextBoxFinds.MatchCase
    5. fOption = fOption Or RichTextBoxFinds.WholeWord
    6. fOption = fOption Or RichTextBoxFinds.Reverse
    7. x = RichTextBox1.Find(txtFind.Text, startAt, endAt, fOption)
    8. MsgBox(x)

  3. #3

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Searching up through richtextbox (not down)

    couldn't get that one to work for me, I tried using this

    vb Code:
    1. Dim x As Integer
    2.         If searchdown.Checked Then
    3.             'We'll define fOption as the richtextbox finds option for searching the text
    4.             Dim fOption As RichTextBoxFinds = 0
    5.             If ckCaseSensitive.Checked Then fOption = fOption Or RichTextBoxFinds.MatchCase
    6.             If ckWholeWord.Checked Then fOption = fOption Or RichTextBoxFinds.WholeWord
    7.             If searchup.Checked Then fOption = fOption Or RichTextBoxFinds.Reverse
    8.  
    9.             If searchdown.Checked Then
    10.                 x = Form1.RichTextBox1.Find(txtFind.Text, PlaceHolder, fOption)
    11.                 PlaceHolder = Form1.RichTextBox1.SelectionStart + 1
    12.             ElseIf searchup.Checked Then
    13.                 x = Form1.RichTextBox1.Find(txtFind.Text, PlaceHolder, 0, fOption)
    14.                 PlaceHolder = Form1.RichTextBox1.SelectionStart - 1
    15.             End If
    16.  
    17.             If x < 0 Then
    18.                 If MessageBox.Show("There are no more occurances of the text " & txtFind.Text & vbCrLf & "or the text does not exist in the document. Would you like to start from the beginning of the document?", "Not found", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
    19.                     PlaceHolder = 0
    20.                     btnFindNext.PerformClick()
    21.                 End If
    22.             End If
    23.         End If

  4. #4

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Searching up through richtextbox (not down)

    Still requesting help on this.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Searching up through richtextbox (not down)

    sorry i meant to reply earlier... got distracted.
    you're using it wrong. when reverse searching, endAt is where it starts searching from + startAt is where it stops searching, like so:

    vb Code:
    1. x = Form1.RichTextBox1.Find(txtFind.Text, 0, PlaceHolder, fOption)

  6. #6

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Searching up through richtextbox (not down)

    Ahh, i've never used the reverse function before, I thought the reverse option would enable it to read the code from the original way, but know to do it in reverse... Thanks lol, that would have really confused me that I was doing it backwards.

    Edit: sh*t lol I can't believe how simple that would have been if I would have known that, I understand the code, I just needed to know how reverse works.... I'll put that in my memory for other finding functions/options in my app, thanks buddy. +1 for that.
    Last edited by AceInfinity; May 28th, 2011 at 07:56 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width