advanced search in RTB

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cengiz Ulku

    advanced search in RTB

    Hi,

    I know now, how to search for a special char. or a word in a RTB control.
    But, my question is:

    My RTF file is some sort of an index document, there are chapter numbers
    and within these chapters, each line is also numbered. For to avoid ambigous
    numbers each chapter number is "Bold, 14pts" and each line is "Bold,
    superscript, 9pts". (Remark: I can not use letters instead of numbers).

    As my program is -working hard- to be a reader for this types of indexes, I
    have 2 textbox controls for the user, one is for the chapter number and the
    other is for the line numbers -Requested number will be highlighted. When
    the user enters the chapter number and line number, e.g. chap. 5, the second
    txtbox should look for only the numbers that are inside the chap. 5. For the
    time being I try to solve this question, the optimum operability will be
    considered later. Help me, please!

    Thanks,
    --
    Cengiz Ulku
    cengizu at bluewin.ch


  • Martin Trump

    #2
    Re: advanced search in RTB

    In article <3f477246$1_3@n ews.bluewin.ch> , Cengiz Ulku
    <cengizu@bluewi n.ch> writes[color=blue]
    >As my program is -working hard- to be a reader for this types of indexes, I
    >have 2 textbox controls for the user, one is for the chapter number and the
    >other is for the line numbers -Requested number will be highlighted. When
    >the user enters the chapter number and line number, e.g. chap. 5, the second
    >txtbox should look for only the numbers that are inside the chap. 5. For the[/color]

    I've just learned to my cost that searching an RTB with .SelStart etc.
    is *unbelievably* slow,

    Possible alternative assuming the list has a fixed layout. Use the
    rtb.Text value. Search that line by line for the line starts that you
    know will be present, "Chap. 1" then "Chap. 2" etc. Between those search
    for line starts "Line 1.", "Line 2." or whatever the format of the line
    numbers is.

    Might give you a start. If it's possible it should be ~500 times faster
    than .SelStart...

    Regards.

    --
    Martin Trump

    Comment

    • Rick Rothstein

      #3
      Re: advanced search in RTB

      > I've just learned to my cost that searching an RTB with .SelStart etc.[color=blue]
      > is *unbelievably* slow,[/color]

      Look up the Find method in the help files for the RichTextBox control.

      Rick - MVP


      Comment

      • Martin Trump

        #4
        Re: advanced search in RTB

        In article <ybmdncZTJ83tL9 qiU-KYuA@comcast.co m>, Rick Rothstein
        <rickNOSPAMnews @NOSPAMcomcast. net> writes[color=blue]
        >One thing very nice about the Find method is that it allows searches for
        >whole words; this allows you to search for the word "the" without finding it[/color]

        Quite so. Probably useful to the OP seeking "Chap. 1" whatever.

        Once again, I live and learn :-)

        Regards.

        --
        Martin Trump

        Comment

        • Cengiz Ulku

          #5
          Re: advanced search in RTB

          Hi!

          Thank you for your help.

          My index file is prepared within Word and saved as rtf format using
          superscripts. In this case I think I should use the RTF code "\super" for to
          find 'em.

          Cengiz Ulku
          cengizu@bluewin .ch




          "Rick Rothstein" <rickNOSPAMnews @NOSPAMcomcast. net> wrote in message
          news:_QGdnUxXPI f2HdqiXTWJiA@co mcast.com...[color=blue][color=green]
          > > I know now, how to search for a special char. or a word in a RTB[/color][/color]
          control.[color=blue][color=green]
          > > But, my question is:
          > >
          > > My RTF file is some sort of an index document, there are chapter[/color][/color]
          numbers[color=blue][color=green]
          > > and within these chapters, each line is also numbered. For to avoid[/color]
          > ambigous[color=green]
          > > numbers each chapter number is "Bold, 14pts" and each line is "Bold,
          > > superscript, 9pts". (Remark: I can not use letters instead of numbers).
          > >
          > > As my program is -working hard- to be a reader for this types of[/color][/color]
          indexes,[color=blue]
          > I[color=green]
          > > have 2 textbox controls for the user, one is for the chapter number and[/color]
          > the[color=green]
          > > other is for the line numbers -Requested number will be highlighted.[/color][/color]
          When[color=blue][color=green]
          > > the user enters the chapter number and line number, e.g. chap. 5, the[/color]
          > second[color=green]
          > > txtbox should look for only the numbers that are inside the chap. 5. For[/color]
          > the[color=green]
          > > time being I try to solve this question, the optimum operability will be
          > > considered later. Help me, please![/color]
          >
          > I wasn't sure how you were doing your superscript as VB doesn't have a
          > built-in way to apply a **true** RTF superscript. It does allow for a
          > selection to have its characters offset (in the vertical direction), so I
          > used that to simulate the superscript for this example. (If you are using[/color]
          a[color=blue]
          > **true** superscript, applied from another application, then post back and[/color]
          I[color=blue]
          > try to modify this to take that into account.) Anyway, this code should[/color]
          find[color=blue]
          > the Chapter Number, which is bolded, specified in a TextBox named Text1[/color]
          and[color=blue]
          > Line Number, which is offset a value of 60, specified in a TextBox named
          > Text2.
          >
          > Rick - MVP
          >
          > Dim IFoundIt As Boolean
          > With RichTextBox1
          > .SelStart = 0
          > .Find Text1.Text
          > If Not .SelBold Then
          > Do Until IFoundIt
          > .Find Text1.Text, .SelStart + 1
          > If .SelBold = True Then IFoundIt = True
          > Loop
          > End If
          > IFoundIt = False
          > .Find Text2.Text
          > If .SelCharOffset <> 60 Then
          > Do Until IFoundIt
          > .Find Text2.Text, .SelStart + 1
          > If .SelCharOffset = 60 Then IFoundIt = True
          > Loop
          > End If
          > .SetFocus
          > End With
          >
          >[/color]


          Comment

          • Cengiz Ulku

            #6
            Re: advanced search in RTB

            Hi,



            Thanks a lot for your help!



            Let me try to explain what really I want to do. I know how to explain but
            not to explain it to VB!!



            Remark1: The index file is created by Word, with superscripted line numbers.

            Remark2: Form contains 2 TBoxes, One for the chapter number and One for the
            line number.



            In fact -what I understand is- these two TBoxes should "communicat e" between
            each other. Text2 should select the text according to Text1's value.



            And the file looks like :

            chapter 1<bold, 14pts>

            1<superscript> reference bla bla bla

            2<superscript>b la bla bla....

            ...

            chapter 2<bold, 14pts>

            1<superscript>a nother bla bla...

            2<superscript>s ome sort of bla bla...

            ....

            etc..



            In a way that VB understands, what I want VB to understand is: (Roughly)

            Chapter = Look for the value in Text1

            Line_number= Look for the value in Text2



            Put Selection at Chapter

            Do find every text (beginning after Chapter)

            Highlight Line_numbers which are superscripted

            Loop until

            Bolded text sized 14pts.

            If all these are not clear, sorry for your eyes, please ignore it.

            Have a nice day!

            --
            Cengiz Ulku
            cengizu@bluewin .ch

            "Cengiz Ulku" <cengizu@bluewi n.ch> wrote in message
            news:3f477246$1 _3@news.bluewin .ch...[color=blue]
            > Hi,
            >
            > I know now, how to search for a special char. or a word in a RTB control.
            > But, my question is:
            >
            > My RTF file is some sort of an index document, there are chapter numbers
            > and within these chapters, each line is also numbered. For to avoid[/color]
            ambigous[color=blue]
            > numbers each chapter number is "Bold, 14pts" and each line is "Bold,
            > superscript, 9pts". (Remark: I can not use letters instead of numbers).
            >
            > As my program is -working hard- to be a reader for this types of indexes,[/color]
            I[color=blue]
            > have 2 textbox controls for the user, one is for the chapter number and[/color]
            the[color=blue]
            > other is for the line numbers -Requested number will be highlighted. When
            > the user enters the chapter number and line number, e.g. chap. 5, the[/color]
            second[color=blue]
            > txtbox should look for only the numbers that are inside the chap. 5. For[/color]
            the[color=blue]
            > time being I try to solve this question, the optimum operability will be
            > considered later. Help me, please!
            >
            > Thanks,
            > --
            > Cengiz Ulku
            > cengizu at bluewin.ch
            >
            >[/color]


            Comment

            • Martin Trump

              #7
              Re: advanced search in RTB

              In article <3f48b7ae_5@new s.bluewin.ch>, Cengiz Ulku
              <cengizu@bluewi n.ch> writes[color=blue]
              >If all these are not clear, sorry for your eyes, please ignore it.[/color]

              Cengiz, why not post a few lines of your list here as plain text?

              Regards
              --
              Martin Trump

              Comment

              • Rick Rothstein

                #8
                Re: advanced search in RTB

                > My index file is prepared within Word and saved as rtf format using[color=blue]
                > superscripts. In this case I think I should use the RTF code "\super" for[/color]
                to[color=blue]
                > find 'em.[/color]

                Okay, what about something like the following code then?

                Rick - MVP

                Dim Chapter As Long
                Dim NextChapter As Long
                Dim CurrentSelStart As Long
                Dim IFoundIt As Boolean
                If Text1.Text Like "*[!0-9]*" Or _
                Text2.Text Like "*[!0-9]*" Then
                MsgBox "Bad Chapter or Line Number!", _
                vbCritical, "Bad Input"
                Else
                With RichTextBox1
                CurrentSelStart = .SelStart
                .SelStart = 0
                Chapter = .Find(Text1.Tex t)
                If Not .SelBold Then
                Do Until IFoundIt
                Chapter = .Find(Text1.Tex t, .SelStart + 1)
                If .SelBold = True Then IFoundIt = True
                Loop
                Else
                If Chapter >= 0 Then IFoundIt = True
                End If
                If IFoundIt Then
                CurrentSelStart = .SelStart
                .SelStart = .SelStart + .SelLength
                Do
                NextChapter = .Find(CStr(1 + Val(Text1.Text) ), _
                .SelStart + 1)
                Loop Until .SelBold = True Or NextChapter = -1
                .SelStart = CurrentSelStart + .SelLength
                .SelLength = 1
                Do While InStr(.SelRTF, "\super") = 0
                Chapter = .Find(Text2.Tex t, .SelStart + 1)
                If Chapter = -1 Then
                .SelStart = CurrentSelStart
                .UpTo vbLf, False
                Exit Do
                End If
                Loop
                If .SelLength > 0 And Chapter >= NextChapter Then
                .SelStart = CurrentSelStart
                .UpTo vbLf, False
                End If
                Else
                .SelStart = CurrentSelStart
                End If
                .SetFocus
                End With
                End If


                Comment

                Working...