-
[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?
-
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
-
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
-
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
-
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.
-
Re: 2 questions
You'll find your answer in this thread by our Richtextbox expert moeur.
-
Re: 2 questions
richtextbox supports hyperlinks. Do a forum search. it is not very easy to use.
-
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.