[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Making a part of the text a url

Posted on 1999-12-18
18
Medium Priority
?
160 Views
Last Modified: 2010-05-02
How do you make a part of the text a url ... like for instance

"blah blah ....
 http://www.experts-exchange.com
 blah blah..."

I think they make it a link automatically on expert-exchange ... but in a text box that has that ... how could i make it a link?
0
Comment
Question by:ThaSmartUno
  • 11
  • 7
18 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 2292264
Depends on what control you're talking about. RTF box, TextBox, Labels, have no knowledge of their content and will ignore URLS as just another string of characters. Web control will recognize the URL, but is essentially impossible to place dynamically created text into and doesn't support editing.

You can code around this with a RTB. The RTB allows you to set colors and underline for portions of text. You could automatically convert the URL into blue/underlined and you could also track the cursor position. In the double click event if you see that you're positioned over a URL then pass the URL to the web control and the page will come up. This would be a moderate effort to code but should work.

If you want the URL to come up *in* the RTB, that's not going to happen. But you can simulate it by laying the web control directly over the RTB and setting the .Visible property to false. When the URL is selected toggle both the RTB and Web controls .visible property (rtb off, web on) and from the users perspective the URL that they just typed will appear.

The Web control supports a [Back] functionality that returns an error when there is no [back] left (you're at the top of the tree...) Anyway, this can then signal that your software should toggle back and hide the web control and have the RTB re-appear so the user can continue editing.

Should work ok, but not trivial to code.

M
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2292380
so if i had a rtf text box ... and it had that in it ... i couldn't make a link?
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2292381
and if i can ... could u paste some code in? Thanks in advance.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 12

Expert Comment

by:mark2150
ID: 2292454
The RTB is not aware that a string starting HTTP is anything other than a series of characters. It doesn't know a "URL" from anything else that is typed into it. You have to look for the string and decide to highlight it.

In the keyup event watch for a space or enter. Then scan the .Text looking for "HTTP" or "WWW".

  IF INSTR(UCASE(RTB.TEXT), "WWW") ...

If you find it search backwards and forwards for the next space of vbCrLf pair to identify the ends of the URL. Use SetStart and SelLenght to highlight the text and apply an underline and color to make it look like a URL.

On the mouse click event look at the .SelStart and if it's between the .SelStart and .SelStart + .SelLength of the URL then you trigger your web control.

For 50 points this is as close to code as I'm going to give...

M
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2292488
how bout this for the code?
0
 
LVL 12

Expert Comment

by:mark2150
ID: 2292925
Ok, I'll see what I can do tomorrow... Too late tonight...

M
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2293358
k thanks ... ill check back either tonight or monday night
0
 
LVL 12

Accepted Solution

by:
mark2150 earned 300 total points
ID: 2296555
Ok. This more or less works. Create a form and place a RichTextBox and a Web control on it. Drop in the following code:

'
' Intranet web browser
' Copyright 1999 - Mark M. Lambert - All Rights Reserved
' By: Mark M. Lambert on June 15, 1999
'
' V2.0.x - 20 Dec 99 - MML - Make RTB hotlink
' V1.0.x - 15 Jun 99 - MML - Initial Code
'
Option Explicit
'

Private Sub Form_Click()
On Error GoTo AtTop
web.GoBack
On Error GoTo 0
Exit Sub
' ===========
'
' Here when we're at top of web tree
'
AtTop:
Resume AtTop1
'
AtTop1:
web.Visible = False
RTB.Visible = True
'
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
'
' Here every time a key is pressed. Watch for space and then if we see one look to see if we just
' typed a URL
'
If Chr(KeyCode) <> " " Then Exit Sub
'
Dim Work        As String
Dim Marker1     As Integer
Dim Marker2     As Integer
Dim Ptr         As Integer
'
Work = RTB.Text
Ptr = 1
'
Marker1 = InStr(Ptr, UCase(Work), "HTTP://", vbTextCompare)
Do While Marker1 > 0
    '
    ' ok, found head of what could be a URL. Look for tail
    '
    Marker2 = InStr(Marker1, Work, " ")
    If Marker2 > Marker1 Then
            RTB.SelStart = Marker1 - 1
           RTB.SelLength = Marker2 - Marker1
            RTB.SelColor = vbBlue
        RTB.SelUnderline = True
    End If
    '
    Ptr = Marker1 + 1
    Marker1 = InStr(Ptr, UCase(Work), "HTTP://", vbTextCompare)
    '
Loop
'
RTB.SelStart = Len(RTB.Text)
RTB.SelLength = 0
RTB.SelUnderline = False
'
End Sub

Private Sub Form_Load()
'
Me.Caption = Me.Caption & " - V" & App.Major & "." & App.Minor & "." & App.Revision
'
web.Top = RTB.Top
web.Left = RTB.Left
web.Width = RTB.Width
web.Height = RTB.Height
web.Visible = False
RTB.Visible = True
'
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'
Dim frm As Form
'
For Each frm In Forms
    Unload frm
    Set frm = Nothing
Next frm
'
End
'
End Sub

Private Sub RTB_Click()
'
Dim Marker1     As Integer
Dim Marker2     As Integer
Dim aChar       As String
'
' Check to see if we're on URL
'
If Not RTB.SelUnderline Then Exit Sub       'Nothing to do if we're not a URL
'
Marker1 = RTB.SelStart
'
Backup:
aChar = Mid(RTB.Text, Marker1, 1)
If (aChar = Space(1) Or aChar = vbLf) Then
Else
    Marker1 = Marker1 - 1
    If Marker1 > 0 Then GoTo Backup
    '
End If
'
' Ok, found start, now look for end
'
Marker1 = Marker1 + 1
Marker2 = RTB.SelStart
'
Forward:
aChar = Mid(RTB.Text, Marker2, 1)
If (aChar = Space(1) Or aChar = vbCr) Then
    If Marker2 > Marker1 Then
        web.Navigate Trim(Mid(RTB.Text, Marker1, Marker2 - Marker1))
        RTB.Visible = False
        web.Visible = True
        Exit Sub
        ' ============
        '
    End If
    '
Else
    Marker2 = Marker2 + 1
    If Marker2 <= Len(RTB.Text) Then GoTo Forward
    '
End If
'
End Sub

This changes text that starts with HTTP:// and ends with a space into blue and underlined and if you click on it (after a delay) the page will appear.

Clicking on the body of the form acts like a [Back] button and when you're all the way back to where you started the RTB re-appears and you're back in edit mode.

Took less than 45 minutes to write from a cold, standing, start.

If you have trouble getting all of the web controls and such loaded simply download the mini-web browser from my web page and use that as the underlying project (which is what I did...)

M

0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2296589
this did not work for me ... I added WebBrowser1 (renamed to Web) and a RichTextBox (renamed to RTB) and i typed in the RTB "http://www.experts-exchange.com " and it didn't work
0
 
LVL 12

Expert Comment

by:mark2150
ID: 2296876
As I said in the last para of my previous post, use the project I referenced as a "seed" for this. You have to have several components loaded over and above the raw controls. It's easier to load the project and paste this code in than it is to hunt for SHDOCVW.OCA and .DLL. All of this is dependent on IE4 or higher being installed on the system.

M


0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2298662
well ...  i have IE 5 ... and what didn't work was that the RTB didn't change the text's colo
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2298664
color that is
0
 
LVL 12

Expert Comment

by:mark2150
ID: 2299153
Try typing it with some other text around it. It worked fine on my system.

Now is the time to visit http://cyberchute.com/rvbus/madmark and see all the fun stuff I have online

M
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2299255
I put a breakpoint inside the sub
"Form_KeyUp" ... right at the first statement ... the If statement ... I started typing stuff ... and it never broke ...
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2299258
I changed it to RTB_KeyUp ... and it works now
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2299262
Thank you
0
 
LVL 12

Expert Comment

by:mark2150
ID: 2299289
I should have mentioned that you had to set the form Keypreview to true...

Sorry. Is problem with sending code and not project...

M
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2299354
=) ... thanx
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

640 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question