Alright, try this code....
With RichTextBox1
CurrentPosition = .SelStart
.SelStart = 0
.SelLength = 1
Do While InStr(.SelRTF, "\super") = 0
Position = .Find(Text1.Text, .SelStart + 1)
If Position = -1 Then
.SelStart = CurrentPosition
Exit Do
End If
Loop
.SetFocus
End With
The above **only** finds the first occurrence if there are multiple
occurrences of the number in your TextBox. You didn't say whether there
could be multiple occurrences of the same number in superscript and whether
you needed to find all of them. I'm going to sleep in a couple of minutes,
so I can't look for a solution of that right now. If you need that, post
back saying so.
Rick - MVP
"Cengiz Ulku" <ce*****@bluewin.ch> wrote in message
news:3f********@news.bluewin.ch...
Thank you Rick!
My Rtf file is not written within my program's RTB control, the file is
written by Word and saved as rtf. As an abnormal char I have only these
superscripts which needs to be found and highlighted when the user looks
for it.
Here is what the text looks like:
^1 Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
^2 sed diem nonummy nibh euismod tincidunt ut lacreet dolore magna aliguam
erat volutpat. Ut wisis enim ad minim veniam
^3 quis nostrud exerci tution ullam corper suscipit lobortis nisi ut
aliquip ex ea commodo consequat. Duis te feugi facilisi. Duis autem dolor
etc...
Thanks a lot in advance!
Cengiz Ulku
ce*****@bluewin.ch
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:f-********************@comcast.com... I've already posted a question similar but will need some precisions
and help.
I have a rtf file displayed within a RTB control. Above it, I have a text box control with a scroller which helps me to increase/decrease
numbers inside it by clicking. (There should be a shorter name for this control!!!)
What I want is: Whenever I click the increase the number button, the
concerned number within my rtf file is selected. The numbers to be
selected are fonts with superscripts not normal fonts. So When I increase the
numbers from 1 to whatever the program will select the superscripted number
but not any other number which may exist in normal form.
If you are using the SelCharOffset property to establish your
superscript, then I would think code something like this will find the first
occurrence of a character specified in Text1 that has its SelCharOffset property
set to anything other than zero. You can use this as a base in case you have to
do multiple consecutive selections or whatever.
Dim Position As Long
Dim CurrentPosition As Long
With RichTextBox1
CurrentPosition = .SelStart
.SelStart = 0
.SelLength = 1
Do While .SelCharOffset = 0
Position = .Find(Text1.Text, .SelStart + 1)
If Position = -1 Then
.SelStart = CurrentPosition
Exit Do
End If
Loop
.SetFocus
End With
Rick - MVP