Connecting Tech Pros Worldwide Forums | Help | Site Map

Finding specific char in a rtf file

Cengiz Ulku
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi,

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 this question is clear, thanks for your replies in advance!
if not please ignore it!
--
Cengiz Ulku
cengizu@bluewin.ch



Rick Rothstein
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Finding specific char in a rtf file


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" <cengizu@bluewin.ch> wrote in message
news:3f374949_4@news.bluewin.ch...[color=blue]
> 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[/color]
for[color=blue]
> 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[/color]
aliquip[color=blue]
> ex ea commodo consequat. Duis te feugi facilisi. Duis autem dolor
> etc...
>
> Thanks a lot in advance!
> Cengiz Ulku
> cengizu@bluewin.ch
>
>
> "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
> news:f-SdnfLICZ7MHKuiXTWJkg@comcast.com...[color=green][color=darkred]
> > > I've already posted a question similar but will need some precisions[/color][/color][/color]
and[color=blue][color=green][color=darkred]
> > > help.
> > >
> > > I have a rtf file displayed within a RTB control. Above it, I have a[/color][/color]
> text[color=green][color=darkred]
> > > box control with a scroller which helps me to increase/decrease[/color][/color][/color]
numbers[color=blue][color=green][color=darkred]
> > > inside it by clicking. (There should be a shorter name for this[/color]
> > control!!!)[color=darkred]
> > >
> > > 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[/color]
> > selected[color=darkred]
> > > are fonts with superscripts not normal fonts. So When I increase the[/color]
> > numbers[color=darkred]
> > > from 1 to whatever the program will select the superscripted number[/color][/color][/color]
but[color=blue][color=green]
> > not[color=darkred]
> > > any other number which may exist in normal form.[/color]
> >
> > If you are using the SelCharOffset property to establish your[/color][/color]
superscript,[color=blue][color=green]
> > then I would think code something like this will find the first[/color][/color]
occurrence[color=blue][color=green]
> > of a character specified in Text1 that has its SelCharOffset property[/color][/color]
set[color=blue]
> to[color=green]
> > anything other than zero. You can use this as a base in case you have to[/color]
> do[color=green]
> > 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
> >
> >[/color]
>
>[/color]


Cengiz Ulku
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Finding specific char in a rtf file


Thanks really a lot Rick, you helped me as I'm a novice programmer.

If you can guide me to a link (if it exists)so that I can learn more details
about the usage of these RTF codes (like \super, \b etc..) because the msdn
library cd's do not supply clear info for such beginner...

Have a nice day!
--
Cengiz Ulku
cengizu@bluewin.ch




----------------------------------
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:ddqdnT1G8NsUyqqiU-KYgw@comcast.com...[color=blue]
> 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[/color]
whether[color=blue]
> 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" <cengizu@bluewin.ch> wrote in message
> news:3f374949_4@news.bluewin.ch...[color=green]
> > 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[/color]
> for[color=green]
> > 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[/color][/color]
aliguam[color=blue][color=green]
> > erat volutpat. Ut wisis enim ad minim veniam
> > ^3 quis nostrud exerci tution ullam corper suscipit lobortis nisi ut[/color]
> aliquip[color=green]
> > ex ea commodo consequat. Duis te feugi facilisi. Duis autem dolor
> > etc...
> >
> > Thanks a lot in advance!
> > Cengiz Ulku
> > cengizu@bluewin.ch
> >
> >
> > "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
> > news:f-SdnfLICZ7MHKuiXTWJkg@comcast.com...[color=darkred]
> > > > I've already posted a question similar but will need some precisions[/color][/color]
> and[color=green][color=darkred]
> > > > help.
> > > >
> > > > I have a rtf file displayed within a RTB control. Above it, I have a[/color]
> > text[color=darkred]
> > > > box control with a scroller which helps me to increase/decrease[/color][/color]
> numbers[color=green][color=darkred]
> > > > 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[/color][/color]
> but[color=green][color=darkred]
> > > not
> > > > any other number which may exist in normal form.
> > >
> > > If you are using the SelCharOffset property to establish your[/color][/color]
> superscript,[color=green][color=darkred]
> > > then I would think code something like this will find the first[/color][/color]
> occurrence[color=green][color=darkred]
> > > of a character specified in Text1 that has its SelCharOffset property[/color][/color]
> set[color=green]
> > to[color=darkred]
> > > anything other than zero. You can use this as a base in case you have[/color][/color][/color]
to[color=blue][color=green]
> > do[color=darkred]
> > > 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
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Don@home.com
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Finding specific char in a rtf file


On Mon, 11 Aug 2003 19:26:04 +0200, "Cengiz Ulku" <cengizu@bluewin.ch> wrote:
[color=blue]
>Thanks really a lot Rick, you helped me as I'm a novice programmer.
>
>If you can guide me to a link (if it exists)so that I can learn more details
>about the usage of these RTF codes (like \super, \b etc..) because the msdn
>library cd's do not supply clear info for such beginner...[/color]

So what else is new, beginner to old timer, it is the same problem with MSDN..
Even M$ most likely doesn't use it... ;->
[color=blue]
>
>Have a nice day![/color]

Have a good day...

Don
Paul W
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Finding specific char in a rtf file



"Cengiz Ulku" <cengizu@bluewin.ch> wrote in message
news:3f37d1a1$1_5@news.bluewin.ch...[color=blue]
> Thanks really a lot Rick, you helped me as I'm a novice programmer.
>
> If you can guide me to a link (if it exists)so that I can learn more[/color]
details[color=blue]
> about the usage of these RTF codes (like \super, \b etc..) because the[/color]
msdn[color=blue]
> library cd's do not supply clear info for such beginner...
>
> Have a nice day!
> --
> Cengiz Ulku
> cengizu@bluewin.ch
>[/color]
This might help.
http://msdn.microsoft.com/library/de...ml/rtfspec.asp


Closed Thread