|
-
May 27th, 2011, 07:11 PM
#1
Thread Starter
Fanatic Member
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:
Dim x As Integer If searchdown.Checked Then 'We'll define fOption as the richtextbox finds option for searching the text Dim fOption As RichTextBoxFinds = 0 If ckCaseSensitive.Checked Then fOption = fOption Or RichTextBoxFinds.MatchCase If ckWholeWord.Checked Then fOption = fOption Or RichTextBoxFinds.WholeWord x = Form1.RichTextBox1.Find(txtFind.Text, PlaceHolder, fOption) PlaceHolder = Form1.RichTextBox1.SelectionStart + 1 If x < 0 Then 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 PlaceHolder = 0 btnFindNext.PerformClick() End If 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.
-
May 27th, 2011, 07:46 PM
#2
Re: Searching up through richtextbox (not down)
try this:
vb Code:
Dim x As Integer
'We'll define fOption as the richtextbox finds option for searching the text
Dim fOption As RichTextBoxFinds = 0
fOption = fOption Or RichTextBoxFinds.MatchCase
fOption = fOption Or RichTextBoxFinds.WholeWord
fOption = fOption Or RichTextBoxFinds.Reverse
x = RichTextBox1.Find(txtFind.Text, startAt, endAt, fOption)
MsgBox(x)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 27th, 2011, 09:19 PM
#3
Thread Starter
Fanatic Member
Re: Searching up through richtextbox (not down)
couldn't get that one to work for me, I tried using this
vb Code:
Dim x As Integer If searchdown.Checked Then 'We'll define fOption as the richtextbox finds option for searching the text Dim fOption As RichTextBoxFinds = 0 If ckCaseSensitive.Checked Then fOption = fOption Or RichTextBoxFinds.MatchCase If ckWholeWord.Checked Then fOption = fOption Or RichTextBoxFinds.WholeWord If searchup.Checked Then fOption = fOption Or RichTextBoxFinds.Reverse If searchdown.Checked Then x = Form1.RichTextBox1.Find(txtFind.Text, PlaceHolder, fOption) PlaceHolder = Form1.RichTextBox1.SelectionStart + 1 ElseIf searchup.Checked Then x = Form1.RichTextBox1.Find(txtFind.Text, PlaceHolder, 0, fOption) PlaceHolder = Form1.RichTextBox1.SelectionStart - 1 End If If x < 0 Then 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 PlaceHolder = 0 btnFindNext.PerformClick() End If End If End If
-
May 28th, 2011, 07:13 PM
#4
Thread Starter
Fanatic Member
Re: Searching up through richtextbox (not down)
Still requesting help on this.
-
May 28th, 2011, 07:40 PM
#5
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:
x = Form1.RichTextBox1.Find(txtFind.Text, 0, PlaceHolder, fOption)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 28th, 2011, 07:53 PM
#6
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|