flash07 10-01-2001, 06:16 PM Hi All
I created a small program with a Form and a MSFlexgrid.
I load up some attribute values into MSFlexgrid and for each values could be a URL. Thus, some logic is required to first determine if the attribute is a URL (e.g.: starts with http, or www, etc). If this is the case, then clicking on the attribute value should cause:
1. IE to be started, with the given URL loaded into a prescribed frame, if IE is not running
2. if IE is running, the URL is loaded into current URL frame.
The question, how can I do this?
cheers
Volte 10-01-2001, 06:21 PM Declare :
<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>
and add:
<pre>ShellExecute Me.hWnd, vbNullString, "http://www.myurlgoeshere.com", vbNullString, "", 1</pre>
to whereever you want it to fire.
-----Edit-----
fixed word-wrap<P ID="edit"><FONT class="small"><EM>Edited by KesleyK on 10/04/01 09:53 AM.</EM></FONT></P>
flash07 10-01-2001, 06:26 PM What's the return values if it is a valid/non valid URL?
cheers
Volte 10-01-2001, 06:48 PM I think it'll just open up the DNS Error page in Internet Explorer... It would do the same thing as if you typed the url into the address bar.
flash07 10-01-2001, 06:57 PM Then how would I determine if it is a non-valid URL then don't load the IE or else load IE.
cheers
Volte 10-01-2001, 07:01 PM the Inet control maybe able to help you on this one. I suggest reading up on the Microsoft Internet Controls.
flash07 10-01-2001, 07:09 PM I think I found a function to check for the internet connection, it uses something like this:
Private Const FLAG_ICC_FORCE_CONNECTION = &H1
Private Declare Function InternetCheckConnection Lib "wininet.dll" _
Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, _
ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
dim sstrText as string
sstrText="http://www.myURLname.com"
If InternetCheckConnection(sstrText, FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
MsgBox "Connection to " & sstrText & " failed!", vbInformation
Else
MsgBox "Connection to " & sstrText & " succeeded!", vbInformation
ShellExecute Me.hwnd, vbNullString, sstrText, vbNullString, sstrNull, 1
End If
cheers
flash07 10-01-2001, 08:10 PM But I still couldn't find a function which can check a certain URL extension (i.e.: myURLName) this could be myURLName.com or myURLName.net or myURLName.com.au, etc.
If anyone outhere knows, pls tell me.
cheers
flash07 10-01-2001, 09:58 PM How can VB check if IE is currently running or not?
cheers
dcl3500 10-01-2001, 10:04 PM This is what I use to detect Word. It is pretty much straight from MSDN. You will need to modify it for IE, but I think it will work.
Public Function FDetectWord() As Boolean
' Procedure dectects a running MSWord and registers it.
Const WM_USER = 1024
Dim hWnd As Long
' If MSWord is running this API call returns its handle.
hWnd = FindWindow("OPUSAPP", 0)
If hWnd = 0 Then ' 0 means MSWord not running.
FDetectWord = False
Exit Function
Else
' MSWord is running
FDetectWord = True
End If
End Function
You can see that the function returns false if the target app is not running and true if it is.
Don
Time is the best teacher; unfortunately it kills all its students.
flash07 10-01-2001, 10:35 PM Thanks, it works with IE.
Good stuff.
flash07 10-01-2001, 10:43 PM I'm having another problem to determine a valid URL from VB.
For example:
A string could be a URL site
dim MyURLName as String
MyURLName = "mydotcom"
How would VB determine "mydotcom" is a valid URL (e.g.: check for mydotcom.com or mydotcom.com.au or mydotcom.net, etc)
Is there any API function does the check?
cheers
dcl3500 10-01-2001, 10:55 PM Man I don't know of an API call for that, but I should think you could use some type of parsing routine to check for valid TLD's. The big problem there is there are so darn many TLD's and they just added another bunch a couple of days ago too, then throw in all the country codes and I see a real nightmare. Of course with my penchant for using databases for the backend I would have to suggest storing them all in a table images/icons/smile.gif. I suppose though it would be possible. Go to someplace like www.register.com (http://www.register.com) and see if you can get a complete listing of them, then pm volteface and see if he would be willing to talk with you about how he did his Syntax Highlighter project. I know there are a couple of others here that have done similar projects recently too.
You know though now that I think further on this. I think you could very likely write a function that uses the inet control to test the url to see if it returns a valid page. Another possibilty is to ping the URL. If it returns an IP address then you should have a good URL. Not neccessarily the right one, but a good one. Not sure how you would go about this, but I am certain someone around here does.
Don
Time is the best teacher; unfortunately it kills all its students.<P ID="edit"><FONT class="small"><EM>Edited by dcl3500 on 10/02/01 12:00 AM.</EM></FONT></P>
flash07 10-01-2001, 11:28 PM Anyway thanks a bunch for your reply.
I hope someone here who done similar project could provide some help.
cheers
ChiefRedBull 10-03-2001, 06:28 AM To check if a URL is valid or not, merely check the end four characters.
<pre><font color=red>Public SUb Check(sURL As String) As Boolean
Check = False
If Right$(sURL,4) = "html" or Right$(sURL,4) = ".htm" Then
Check = True
End If
End Sub
</pre></font color=red>You could also stick a checker for the start of the string as well....
<pre><font color=red>If Left$(sURL,7) = "http://" or Left$(sURL,3) = "www" Then
Check = True
End If
</pre></font color=red>As well as checking for ".html" or "http://" you could also check for image extensions, javascript, css etc etc using the same method.
Chief
"How are we to learn, if those that know will not teach... ?" - Me.
a simple way would be to use the inet control with some code like this
<pre><font color=blue>Private Sub</font color=blue> Command1_Click()
Text2.Text = Inet1.OpenURL(Text1.Text)
<font color=blue>If</font color=blue> Text2.Text = "" <font color=blue>Then</font color=blue>
MsgBox "invalid"
<font color=blue>Else</font color=blue>
MsgBox "ok"
<font color=blue>End If</font color=blue>
<font color=blue>End Sub</font color=blue></pre>
flash07 10-03-2001, 04:31 PM Thanks alot guys, very much appreciated.
dcl3500 10-03-2001, 10:17 PM Ok to put a finer point on the idea I had about pinging a url. The Hand has been gracious enough to provide us with a ready built method of doing so. This is it (http://www.visualbasicforum.com/bbs/showflat.php?Cat=&Board=CodeLib&Number=54084&page=0&view=collapsed&sb=5&o=7&part=). Now my idea was to not only see if the url is a proper url but a working url too. Using The Hand's ping thing and using the returned results we can test to see if the url is a real working address by testing whether not passing it a www address returns an IP.
Well that's it I thought it might be nice to know we had a real working address not one with a typo in it or missing extension.
Don
Time is the best teacher; unfortunately it kills all its students.<P ID="edit"><FONT class="small"><EM>Edited by dcl3500 on 10/03/01 11:23 PM.</EM></FONT></P>
flash07 10-04-2001, 04:31 AM Thanks for some input, this really helps, great stuff!
cheers
|