Results 1 to 17 of 17

Thread: [RESOLVED] RTF search and get

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Resolved [RESOLVED] RTF search and get

    Hi guys,

    Wanted to ask...

    im using the find function in rtf, and when the text is found i get the number of the postion...now i would like to know how to get the text from that position + the next 10 chars?

    im pretty lame with that selstart, sellength thing
    Thanks for helping me out.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: RTF search and get

    Are you searching for specific words that, when found, you want to highlight?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: RTF search and get

    Well...i dont need to highlight them...i just need to extract them out of that rtf box and only what i need to trasnfer to another place....
    Thanks for helping me out.

  4. #4
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: RTF search and get

    Code:
    With rtb
    .SelStart = .Find("Texttofind")' Change to the word to find
    .SelLength = 10
    MsgBox .SelText
    text1 = .Seltext
    .SelText = "" 'delete the text ?
    End With
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: RTF search and get

    Quote Originally Posted by isnoend07
    Code:
    With rtb
    .SelStart = .Find("Texttofind")' Change to the word to find
    .SelLength = 10
    MsgBox .SelText
    text1 = .Seltext
    .SelText = "" 'delete the text ?
    End With
    can it be changed so it will get the second results not the first one??


    Thanks for the code!!
    Thanks for helping me out.

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: RTF search and get

    Do you mean, you want to ignore the first "find"?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: RTF search and get

    Delete the 2nd occurance of string
    I got it
    With rtb
    .SelStart = .Find(Texttofind) ' Change to the word to find
    .SelLength = Len(Texttofind)
    .SelStart = .Find(Texttofind, .SelStart + .SelLength)
    .SelLength = Len(Texttofind)
    .SelText = ""
    End With
    Last edited by isnoend07; Feb 17th, 2009 at 01:29 PM.
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  8. #8
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: RTF search and get

    This will not only get the 2nd but whichever occurance you want...

    http://www.vbforums.com/showpost.php...35&postcount=3
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: RTF search and get

    Quote Originally Posted by koolsid
    This will not only get the 2nd but whichever occurance you want...

    http://www.vbforums.com/showpost.php...35&postcount=3
    Yeah i want to find only the second occurence...

    ill try that guys....
    sorry i was not home the entire day so i could reply...not its 2 am almost...im gogin to sleep, ill try that tomorrow


    thanks alot!!!!!!!!!!
    Thanks for helping me out.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: RTF search and get

    It worked out great..

    but would it be possbile to start from where i found a specific word and to take the string until i get to lets say this char ";" ?

    hmmm


    thanks for the help man!
    Thanks for helping me out.

  11. #11
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: RTF search and get

    would it be possbile to start from where i found a specific word and to take the string until i get to lets say this char ";" ?
    yes it is possible.. you will have to amend the function a bit... let me see what can i do I am going out with my wife in few minutes and will be back quite late... but i will post the codes the moment i get the first chance...

    Edit

    Okay, apparently we didn't go .

    Here it is....

    Create a Form, Commandbutton and 1 RTB. Just Run it...

    This example finds the third occurance of "Sid" and then finds the first occurance of ";" and then gives you the string in between...

    I am sure that this code can further be shortened. I have commented the code so you won't have trouble understanding what I did

    Hope this helps...

    Code:
    Option Explicit
    Dim Ret
    Dim FoundStrpos As Long, FoundStrLen As Long, CurInitStart As Long
    Dim CurInitLen As Long, lngCount As Long, lColor As Long, pos As Long
    Dim StrLen As String, MyArray() As String, TempString As String
    
    Private Sub Form_Load()
        'Getting sample text
        RichTextBox1.Text = " I was on my way to meet Sid. Sid was not available. " _
        & "His Friend informed that Sid is out of town ; I left after that..."
    End Sub
    
    Private Sub Command1_Click()
        '-- USAGE
        '-- FindText(RichTextBox1, Search String, nth occurance, String to search after that)
        
        '-- Will find 3rd occurance of "Sid" and Then find first occurance of Semi-Colon
        '-- if found, will give you the middle string "is out of town" in this case
        Ret = FindText(RichTextBox1, "Sid", 3, ";")
    End Sub
    
    Private Function FindText(Rich As RichTextBox, sFindString As String, Numb As Integer, StrSearch As String)
        
        lColor = vbGreen '-- Color for "Sid"
        
        '-- Save the cursor's current length and location
        CurInitStart = Rich.SelStart
        CurInitLen = Rich.SelLength
        
        '-- Length of the string to find
        FoundStrLen = Len(sFindString)
    
        '-- Find the first match of "Sid"
        FoundStrpos = Rich.Find(sFindString, 0, , rtfNoHighlight)
        If FoundStrpos > -1 Then
            Rich.SelStart = FoundStrpos
            Rich.SelLength = FoundStrLen
            lngCount = lngCount + 1
        End If
        
        While FoundStrpos > -1
            '-- Exception -- if you want to JUST find the first occurance
            If Numb = 1 Then
                '-- if found "Sid" then color GREEN
                Rich.SelColor = lColor
                
                '-- Get in between string
                Call InBetweenString(Rich)
                
                '-- Assign any number below -1 to get out of loop
                FoundStrpos = -2
            ElseIf lngCount > 0 And lngCount < Numb Then
                'Attempt to find the next match for "Sid"
                FoundStrpos = Rich.Find(sFindString, _
                FoundStrpos + FoundStrLen, , rtfNoHighlight)
                
                Rich.SelStart = FoundStrpos
                Rich.SelLength = FoundStrLen
                
                '-- if found
                If lngCount = (Numb - 1) Then
                    '-- Color Search String "Sid" in GREEN
                    Rich.SelColor = lColor
                    '-- Get in between string
                    Call InBetweenString(Rich)
                End If
                
                '-- Increment Count
                lngCount = lngCount + 1
            Else
                '-- Assign any number below -1 to get out of loop
                FoundStrpos = -2
            End If
        Wend
    
        '-- Restore the cursor to its original status
        Rich.SelStart = CurInitStart
        Rich.SelLength = CurInitLen
    End Function
    
    Sub InBetweenString(Rich As RichTextBox)
        Dim StrSearch As String, sFindString As String
        
        StrLen = FoundStrpos + FoundStrLen
        Rich.SelStart = StrLen
        StrLen = StrLen - 1
        Rich.SelLength = Len(Mid(Rich.Text, StrLen, Len(Trim(Rich.Text)) - StrLen))
                    
        '-- Get the entire RTB string after the occurance of "Sid"
        TempString = Rich.SelText
                    
        '-- Search for ";"
        pos = InStr(1, TempString, ";")
                   
        '-- If ";" is found
        If pos <> 0 Then
            MyArray = Split(TempString, ";")
                    
            '-- Display the String
            MsgBox MyArray(0)
        Else
            '-- Inform user that ";" doesn't exist
            MsgBox "There is no occurance of " & _
            "'" & StrSearch & "'" & _
            " in the RTB after " & _
            "'" & sFindString & "'"
        End If
    End Sub
    Last edited by Siddharth Rout; Feb 18th, 2009 at 10:22 AM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: RTF search and get

    thank you!!!!

    see ya later then!
    bye
    Thanks for helping me out.

  13. #13
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: RTF search and get

    Updated the code in post 11
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: RTF search and get

    Great code m8!

    Great job!

    It works perfectly!!!!!!!!!!!!!

    RATING you!
    Thanks for helping me out.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: [RESOLVED] RTF search and get

    It works fine but when i do this:

    Code:
    p1 = FindText(txtLoginW, "TEXT1", 2, ";")
    
        p2 = FindText(txtLoginW, "TEXT"", 2, ";")
    
        p3= FindText(txtLoginW, "TEXT3", 2, ";")
    I get only the first result from p1.....from MyArray(0)

    It would be nice to get the found data on P1...

    Can i do that somehow?

    Thanks for the help m8!
    Thanks for helping me out.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: [RESOLVED] RTF search and get

    Ok what i did is :

    1.Put this at the end of the FindText function:

    CurInitLen = 0
    lngCount = 0
    pos = 0


    2. at the end of the FindText :

    findtext = myarray(0)


    that's it


    Cheers
    Thanks for helping me out.

  17. #17
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: [RESOLVED] RTF search and get

    Quote Originally Posted by batori
    It works fine but when i do this:

    Code:
    p1 = FindText(txtLoginW, "TEXT1", 2, ";")
    
        p2 = FindText(txtLoginW, "TEXT"", 2, ";")
    
        p3= FindText(txtLoginW, "TEXT3", 2, ";")
    I get only the first result from p1.....from MyArray(0)

    It would be nice to get the found data on P1...

    Can i do that somehow?

    Thanks for the help m8!
    this line has a double quote: p2 = FindText(txtLoginW, "TEXT"", 2, ";")
    should this be TEXT2 ?"TEXT""
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

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