|
-
Oct 26th, 2007, 06:28 AM
#1
Thread Starter
Addicted Member
[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?
-
Oct 26th, 2007, 06:42 AM
#2
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
-
Oct 26th, 2007, 07:20 AM
#3
Lively Member
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
-
Oct 26th, 2007, 07:50 AM
#4
Lively Member
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
-
Oct 26th, 2007, 07:51 AM
#5
Thread Starter
Addicted Member
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.
-
Oct 26th, 2007, 08:06 AM
#6
Re: 2 questions
You'll find your answer in this thread by our Richtextbox expert moeur.
-
Oct 26th, 2007, 08:08 AM
#7
Re: 2 questions
richtextbox supports hyperlinks. Do a forum search. it is not very easy to use.
-
Oct 26th, 2007, 08:33 AM
#8
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|