Results 1 to 9 of 9

Thread: Hyperlink

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    2

    Exclamation

    I need to know how to add a web hyperlink in my project
    ie to open a web browser at a particular site.

    thankyou

  2. #2
    Hyperactive Member Zaphod64831's Avatar
    Join Date
    Mar 2000
    Posts
    268
    Add these subs:
    Code:
    Public Sub gotoweb(URL As String)
    Dim Success As Long
    
    Success = ShellExecute(0&, vbNullString, URL, vbNullString, "C:\", SW_SHOWNORMAL)
    
    End Sub
    
    Public Sub sendemail(Email As String)
    Dim Success As Long
    
    Success = ShellExecute(0&, vbNullString, "mailto:" & Email, vbNullString, "C:\", SW_SHOWNORMAL)
    
    End Sub
    Then you call them like this:
    Code:
    Private Sub LblURL_Click()
    gotoweb("http://www.your-homepage-here.com")
    End Sub
    
    Private Sub LblEmail_Click()
    sendemail("[email protected]")
    End Sub
    Hope this helps!
    Email: [email protected]

    Home Page: www.olemac.net/~hutch

    I'm bored, VERY bored, and I got bored with my sig. So I changed it to this.

  3. #3
    Hyperactive Member Zaphod64831's Avatar
    Join Date
    Mar 2000
    Posts
    268
    I forgot, you also have to insert this code:
    Code:
    Public 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
    
    Public Const SW_SHOWNORMAL = 1
    Email: [email protected]

    Home Page: www.olemac.net/~hutch

    I'm bored, VERY bored, and I got bored with my sig. So I changed it to this.

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Damn! beat me to it!

    The advantage of this is that it's not reliant on MS Internet explorer. It uses the default browser. I'm almost finished an OCX using this on a label where you can set:

    Hyperlink1.Caption = "VB World"
    Hyperlink1.Link = "Http://www.vb-world.net/"

    (Just thought I'd take a moment to pat myself on the back )

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  5. #5
    Junior Member
    Join Date
    Aug 2000
    Posts
    16
    Success = ShellExecute(0&, vbNullString, URL, vbNullString, "C:\", SW_SHOWNORMAL)


    isn't the "C:\" slightly dangerous? What if there is no C:\ drive on the system? Say the 1st drive starts with D:\.

    I am new to VB but this looks slightly dangerous. IS there an alternative method ?
    ----

    http://www.learntogo.f.net

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    The lpDirectory parameter that Zaphod64831 suggests that you pass "C:\" to is only the preferred working directory for the application.

    Even if C:\ doesn't exist you wouldn't get any errors the app (or Windows) would just designate an other working directory. You can also pass vbNullString to this parameter if you like.

    And by the way, since others take there time to pat there back I thought I would do the same Please read my tip (and download the demo) on how to add hyperlink capability to a RichTextBox.

    Best regards

  7. #7
    Guest
    Most likely the users main drive will be C:\. But if you'd rather have the user tell you what drive they want:

    Code:
    x = InputBox("What is your default drive?",,"C:\")
    If x = "" Then Exit Sub
    Success = ShellExecute(0&, vbNullString, URL, vbNullString, "" & x & "", SW_SHOWNORMAL)
    You should ask that first, than save it to a file so the user doesn't have to answer again. Read/Write to an ini file for that. And no, I don't think calling C:\ will hurt you at all.

  8. #8
    Junior Member
    Join Date
    Aug 2000
    Posts
    16
    You should ask that first, than save it to a file so the user doesn't have to answer again. Read/Write to an ini file for that. And no, I don't think calling C:\ will hurt you at all. [/B]
    I see what you mean. And jsut for clarification .. "think" as in the code will still work or as in most uses have a c:\ drive ?

    -jfs
    ----

    http://www.learntogo.f.net

  9. #9
    Guest
    Correction: I know it won't hurt you.

    The only thing that could probably hurt you is if you kill/delete any important files on C drive.
    Using ShellExecute will not harm you in any way. If you would rather have it so that the user doesn't get an error, if any should occur. Then do this:

    Code:
    On Error Resume Next
    Success = ShellExecute(0&, vbNullString, URL, vbNullString, "C:\", SW_SHOWNORMAL)
    That will ignore any errors completely. You are thinking of something bad happening. Think good thoughts and leave it the way it is! Most of your users will have C drive as there main drive. If they don't than just tell them to email you so you could edit the program and resend it.

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