Results 1 to 23 of 23

Thread: webrowser

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    62

    webrowser

    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

  2. #2
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: webrowser

    try setting the label from on_completed

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    62

    Re: webrowser

    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

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    62

    Re: webrowser

    I tried but it seems not working

    Code:
    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

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: webrowser

    Code:
    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.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: webrowser

    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

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    62

    Re: webrowser

    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

  8. #8
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: webrowser

    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.

  9. #9
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: webrowser

    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 think thats right ( getting on a bit here )

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    62

    Re: webrowser

    Quote Originally Posted by jmsrickland View Post
    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

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: webrowser

    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

  12. #12

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    62

    Re: webrowser

    Quote Originally Posted by westconn1 View Post
    did you read post #6?
    need appropriate help please

  13. #13
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: webrowser

    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

    hope that helps

    if not please shout

  14. #14
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: webrowser

    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
    Attached Files Attached Files
    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.

  15. #15
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: webrowser

    Quote Originally Posted by jmsrickland View Post
    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?

  16. #16
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: webrowser

    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.

  17. #17
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: webrowser

    how do you test for a lack of google
    if pDisp.locationname ="Google"
    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

  18. #18
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: webrowser

    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.

  19. #19
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: webrowser

    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

  20. #20
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: webrowser

    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.

  21. #21

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    62

    Re: webrowser

    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

  22. #22
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: webrowser

    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

  23. #23
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: webrowser

    Quote Originally Posted by westconn1 View Post
    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.

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