Results 1 to 8 of 8

Thread: [RESOLVED] 2 questions

  1. #1

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Resolved [RESOLVED] 2 questions

    The first, hopefully most answerable one - can you get individual buts text (say, in a richtext box) to be a hyperlink? So if I had something saying "For more information, see here", the underlined text would become a hyperlink to a webpage, or some visual basic code.

    The second one: How would I scan a piece of text (again, in a richtext box) for a tag, or a word (eg &i), then look for an identical tag or word further on (eg, it has found &i .... &i), and select the piece of text in between?

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: 2 questions

    for the first one you can get your bits of text, test to see if it looks like a valid url address of some type, convert to html code and save as a htm file

    for the second you wold use instr to find the first string, to get the starting position, then use instr again, starting from the found position to find the finish position, then either select the text inbetween the positions or use mid to read the text inbetween into a variable
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Lively Member
    Join Date
    Oct 2007
    Posts
    68

    Re: 2 questions

    Although I'm only marginally familiar with the RichTextBox, one approach I use is to execute the .Find method of the richtextbox initially (which automatically finds the whole word) and then allow the client to press F3 for subsequent searches.

    Code:
    Private Sub RichTextBox_KeyDown(KeyCode As Integer, Shift As Integer)
    
        Static RetVal        As Long
        Static strSearch    As String
        
        With RichTextBox
           
            '//repeat last search
            If KeyCode = vbKeyF3 Then
                If RetVal = 0 Then
                    RetVal = 1
                End If
                RetVal = InStr(RetVal + 1, UCase$(.Text), strSearch)
                If RetVal <> 0 Then
                    .SelStart = RetVal - 1
                    .SelLength = Len(strSearch)
                End If
            
            '//search form for input value
            ElseIf (Shift And 2) And (KeyCode = vbKeyF) Then
                strSearch = Trim$(UCase$(InputBox("Find Value: ", "Enter Search 
    Values")))
                If Trim$(strSearch) <> "" Then
                    RetVal = RichTextBox.Find(strSearch, RichTextBox.SelStart, Len(RichTextBox))
    
        End With
    
    End Sub

  4. #4
    Lively Member
    Join Date
    Oct 2007
    Posts
    68

    Re: 2 questions

    Accidentally chopped off some code. If it finds a word, I modify the CTRL+F keycode to be 0 so the KeyCode doesn't overlay the highlighted found word with "F" (a bit hokey, but it works).

    Code:
            ElseIf (Shift And 2) And (KeyCode = vbKeyF) Then
                strSearch = Trim$(UCase$(InputBox("Find Value: ", "Enter Search 
    Values")))
                If Trim$(strSearch) <> "" Then
                    RetVal = RichTextBox.Find(strSearch, RichTextBox.SelStart, Len(RichTextBox))
    
                    If RetVal <> 0 Then
                        KeyCode = 0
                        .SelStart = RetVal 
                        .SelLength = Len(strSearch)
                    End If
                End If

  5. #5

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Re: 2 questions

    Thanks for both suggestions.

    westconn, for the hyperlink bit, could you give a practical example? I'm not quite sure what you mean.

  6. #6

  7. #7
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: 2 questions

    richtextbox supports hyperlinks. Do a forum search. it is not very easy to use.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  8. #8

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Re: 2 questions

    Thanks, MartinLiss. That however looks fairly complicated (yet I haven't a clue why I didn't usee the search first ) Ah well, at least the thread had some use with the other question.

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