Results 1 to 6 of 6

Thread: Searching up through richtextbox (not down)

Threaded View

  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.

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