Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clickable label/variable to website 3

Status
Not open for further replies.

SitesMasstec

Technical User
Sep 26, 2010
470
1
18
BR
Hello colleagues:

I have a memory variable and I am able to show it in a form, that's ok (Label box, Caption: =lblNome)

Now, I want to transform it as a link to a website, that is, the lblNome label to be clickable, and when I run the form and click on the label, it opens the default browser and go to a website.

I already do this with images, for many years. Now I want to do the same with a variable. Is it possible?


Thank you,
SitesMasstec
 
Good to see you have it working, SitesMasstec.

One other point: You only need to execute ShellExecute() once during the session - not every time the image is clicked. I usually do it in the startup code in my main program, along with certain other API declarations. That way, you can sort of consider it part of the language.

Doing it in the image's Click event will still work, of course, but each time you do so, you will be consuming a little extra resources (albeit a very small amount).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,

you mean declare, not execute, of course ShellExecute must be executed every time the image is clicked.

Chriss
 
Well, as a website may have its address changed, I went further and created a setting for the user of the application to type any site address:

ConfiWebsites_hcha8d.jpg


freightanchor.com/resources-sea-ports-codes is stored on Public variable yEndePortos1

I declared the ShellExecute in the main program only, as you my colleagues advised me.

In the form I put a label, with the Click Event:

Code:
ShellExecute(0,'open',&yEndePortos1, '', '', 1)

When I ran the program, I clicked on the label and got the Program Error:
Alias 'FREIGHTANCHOR' is not found

Thank you,
SitesMasstec
 
You need

Code:
ShellExecute(0,'open',yEndePortos1, '', '', 1)
No macro substitution, just using the input as a value.

But this will fail, if the URL does not have https:// or http:// in front, or www.
Read back all I already wrote.

What's of major importance is this:
myself said:
ShellExecute mainly expects a filename, not a URL, it's not the major use of ShellExecute to start a browser and let that navigate to a URL. Therefore you need to make it obvious to ShellExecute the passed in parameter is a URL and not a filename. A .com somewhere in the string and usage of slashes instead of backslashes is not unmistakenly pointing out a URL.

Starting the filename parameter of ShellExecute with http:// or https:// is not only a little hint for ShellExecute, it makes it total obvious and ensures, ShellExecute will deal with that as a URL and find the standard browser to start it and pass in that URL to navigate to it.

Chriss
 
Yes Chris, I took out the macro substitution and put https:// in front of the website address, and it worked!


Thank you,
SitesMasstec
 
A way to make it easy for the user to choose http:// or https:// is to make the input with two controls, a combobox for choosing http:// or https:// and then a textbox for the rest of the URL.

Chriss
 
SitesMasstex said:
put https:// in front of the website address
That will work in 99% of times, but a website not running on secure http will still cause an error, so the user has to specify which protocol or scheme - http:// or
Chriss
 
Good idea, Cris!

I implemented it in the sites configuration program in the project:
ConfiWebsites2_oaf6rw.jpg

As VFP and/or Windows considers the variable ' (and also ' as a reserved word (or link) I used http and https in the combobox and '://' as a label, then:
Code:
yWebSitePortos1 = ALLTRIM(yHttpPortos1) + "://" + yEndePortos1    
yWebSitePortos2 = ALLTRIM(yHttpPortos2) + "://" + yEndePortos2
to use the clicable link.

Thank you,
SitesMasstec
 
Looks nice, I assume you make https the default, then users rarely need to chnge this.

One further idea is to also offer the empty option, so the rightside part could contain something that's not even yet invented or something very old like gopher:// or something unusual like ftp://

Chriss
 
Oh, aand another idea, assume someone copies a URL from a browser into your form, then a) the empty option would be fine to not need to cut off the https:// portion, or you program in the textboxes Interactivechange event:

Code:
If lower(left(this.value,6))='[URL unfurl="true"]https://'[/URL]
          yWebSitePortos1 = 'https'
          this.value = substr(this.value,7)
Endif

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top