I need help to set the url at the form load event .. if url found label.enabled=true if not label.enabled=false . that means if internet is connected label enabled otherwise disabled
on form load the label is set to disabled .. and on form load webrowser is set to an URL .. if url is found label gets enabled if webbrowser get an error like server not found or rror like 404 then label remains disabled .. need help with code please
Private Sub Form_Load()
If Timer1.Enabled = True Then
label1.Enabled = True
Else
label1.Enabled = False
End If
End Sub
Private Sub Timer1_Timer()
WebBrowser1.Navigate "http:\\www.google.com"
Timer1.Enabled = False
End Sub
Dim MyURL
Private Sub Form_Load()
Label.Enabled = False
MyURL = "http://www.google.com"
WebBrowser1.Navigate MyURL
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If InStr(URL, MyURL) > 0 Then
Label.Enabled = True
End If
End Sub
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
wouldn't url still be the navigation, even in the case of a 404 or other error, generated by no internet connection
probably need to parse the loaded page, for some criteria, or see if pDisp.locationname matches the expected return
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Sir, jmsrickland .. the label remains disabled even if URL is found and even if URL is not found [without internet connection] .. in both cases Label remain disabled .. even I tried greater and lesser like >, <, <> all the way but no success
I tested that code several times and it worked correctly. Are you using exactly the same code I posted. Also is the name of your label Label or Label1. I use Label so make sure the name is correct
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
if you look at his on_complete you will see that he tests the url against the url he wants... the url with be either the correct url and so >0 returned or the RES:404 url which will not match in any way
I tested that code several times and it worked correctly. Are you using exactly the same code I posted. Also is the name of your label Label or Label1. I use Label so make sure the name is correct
yes yes, I have made label1 instead of label .. but after even without internet connection label remains enabled .. whereas I wish it be disabled if url=server not found
even without internet connection label remains enabled
did you read post #6?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
can you see the result of the attempt to get to url, if as #6, the on_complete is still returning "MYURL" you may need to parse the errormessage displayed so that you can detect a failure to get the url wanted. simply test the returned page for a unique but always present sentence error code or something and use that to fire the boolean state
I include a zip of the project. I tested it several times and it does what you ask. If you see Google in the WebBrowser window then you know it is working and the label becomes enabled
Last edited by jmsrickland; Jan 4th, 2014 at 01:16 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
I include a zip of the project. I tested it several times and it does what you ask. If you see Google in the WebBrowser window then you know it is working and the label becomes enabled
how do you test for a lack of google so that the label reflects this condition?
I had to change the project in the zip. I had a condition wrong but it is working now
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Using pDisp.locationname you need to know the Title and not the URL
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Using pDisp.locationname you need to know the Title and not the URL
yes exactly, but as it is a test page, that will always be the same in form load, the locationname would be reasonable constant, though the user being able to update it and the url, in case for some reason either was changed, would have merit
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
OK, but my approach doesn't require you to know the title. It will always compare on MyUrl which is the URL entered against the event URL which will always have at least what is in myUrl when the page is loaded.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
in my case I don't need to keep webbrowser1 visible to user .. it is just to play a trick if internet connected label1.enabled=true else label1.enabled=false
It will always compare on MyUrl which is the URL entered against the event URL which will always have at least what is in myUrl when the page is loaded.
in some systems at least ( i am sure mine would not be the only one), the returned URL in on complete matches the url navigated to, regardless of whether the correct page loads or some error page loads, even if networking is disabled
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
in some systems at least ( i am sure mine would not be the only one), the returned URL in on complete matches the url navigated to, regardless of whether the correct page loads or some error page loads, even if networking is disabled
Interesting, I did not know that. I use only XP/SP2 and I don't recall that ever happening to me; it has always given correct results that matched the page loaded. Even though your approach will work for OP because he is specifying a particular URL and he knows the Title to look for so using pDisp would only work providing user knows ahead of time what Title to look for. I was just providing a general generic approach so anyone only needs to know the URL and not the Title. However, if it fails on some systems as you say it does then I suppose OP or anyone will simply have to decide on which approach best fits and works for their needs.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.