|
-
Jun 30th, 2000, 09:50 PM
#1
Thread Starter
New Member
I need to know how to add a web hyperlink in my project
ie to open a web browser at a particular site.
thankyou
-
Jun 30th, 2000, 10:20 PM
#2
Hyperactive Member
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!
-
Jun 30th, 2000, 10:37 PM
#3
Hyperactive Member
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
-
Jun 30th, 2000, 11:37 PM
#4
Fanatic Member
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!)
-
Aug 6th, 2000, 08:38 PM
#5
Junior Member
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
-
Aug 6th, 2000, 08:55 PM
#6
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
-
Aug 6th, 2000, 08:59 PM
#7
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.
-
Aug 6th, 2000, 09:30 PM
#8
Junior Member
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
-
Aug 6th, 2000, 10:26 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|