Results 1 to 10 of 10
  1. #1
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,449
    Thanks
    1
    Thanked 1 Time in 1 Post

    Hyperlink in a Label (VB 6)

    <img src=/S/hello.gif border=0 alt=hello width=25 height=29> Loungers

    Can I have the text of a label be a hyper link to a web site, so that when the User clicks it it will launch the browser and then go to that page?

    Thanks

    Wassim <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hyperlink in a Label (VB 6)

    Yes, quite easy. Just create (actually the VBE will create it for you!) the label1_click() event. Put your hyperlink code in that event. Done. Need hyperlink code?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Hyperlink in a Label (VB 6)

    Wassim,

    You can use the ShellExecute API. Place the folllowing at the top of the userform <pre>Private Declare Function ShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long</pre>

    You can then place a label with an url as a caption, and use the following code the Label_Click event <pre>
    Private Sub Label1_Click()
    ShellExecute 0, vbNullString, Me.Label1, vbNullString, "C:", 1
    End Sub</pre>

    changing Label1 to whatever name you give your lable. You can also give it an appropriate color.

    Clicking on the label should launch your browser and display the particula webpage. You can easily launch Word and Excel documents by giving a filename as caption, including the path.

    Andrew C

  4. #4
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,449
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Hyperlink in a Label (VB 6)

    <img src=/S/hello.gif border=0 alt=hello width=25 height=29> Kevin

    Yes while I am working with Andy's code, I would appreciate any examples you may have.

    Oh if I change the hyperlink URL at run time, I guess I would need to pass it some parameter(s) and change the destination as well?

    Thanks.

    Wassim <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  5. #5
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,449
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Hyperlink in a Label (VB 6)

    <img src=/S/hello.gif border=0 alt=hello width=25 height=29> Andrew

    OK so what is the string <font color=blue> "C:" </font color=blue>? is that where I put the URL?

    Thanks again for saving me, you will get your reward someday <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>.

    Wassim <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hyperlink in a Label (VB 6)

    I concur with Andrew. Use ShellExecute. Very flexible and fast and has good error reporting.

    Consider using the tag property to hold the url. Your code can push any value there; then pass "label1.tag" into shellexecute as the "file" parameter. That way, the actual label text can display a human readable name while the url that access the site is hidden in the tag property.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Hyperlink in a Label (VB 6)

    Wassim,

    ShellExecute likes to be given a default directory, and C: seems as good as any in these circumstances.

    As Kevin wisely suggest the Tag property of the Label might be a good place for the url. Say you wanted to Hyperlink to the Lounge, you could set the caption to Woody's Lounge, and the tag to http://www.wopr.com/cgi-bin/w3t/wwwthreads.pl?Cat=

    Then use

    ShellExecute 0, vbNullString, Me.label1.tag, vbNullString, "C:", 1.

    The trailing indicates the the window is to be opened Normal. If you need to guaranteed a maximised window use 3.

    Andrew

  8. #8
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    New York
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hyperlink in a Label (VB 6)

    Resurrecting this years old thread in order to ask:

    What would be the Mac equivalent of the ShellExecute solution?

    Has anyone had to do a cross platform compataible version of this?

    Thanks

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Hyperlink in a Label (VB 6)

    I'm afraid there are few Mac programmers active here. Although we have some Mac fans in the Lounge, the focus is on PC/Windows.

  10. #10
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hyperlink in a Label (VB 6)

    > should launch your browser

    Thanks Andrew. I've been placing my web site on my GUI forms, and this evening realised I could encourage users to visit my web site!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •