Results 1 to 14 of 14

Thread: WebBrowser Problems

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    7

    WebBrowser Problems

    Hello All,

    I am currently making a WebBrowser in Visual Basic 6 using Microsoft Internet controls. I have a few problems and questions, but first i will show you my code. It is fairly basic.

    Code:
    Private Sub gobutton_Click()
    On Error Resume Next
    WebBrowser1.Navigate (urlbar.Text)
    End Sub
    
    Private Sub backbutton_Click()
    On Error Resume Next
    WebBrowser1.GoBack
    End Sub
    
    Private Sub forwardbutton_Click()
    On Error Resume Next
    WebBrowser1.GoForward
    End Sub
    
    
    Private Sub homebutton_Click()
    On Error Resume Next
    WebBrowser1.gohome
    End Sub
    
    Private Sub refreshbutton_click()
    On Error Resume Next
    WebBrowser1.Refresh
    End Sub
    
    
    Private Sub urlbar_KeyDown(KeyCode As Integer, Shift As Integer)
     If KeyCode = vbKeyReturn Then
        WebBrowser1.Navigate (urlbar.Text) 'similar to acceptbutton
     End If
    End Sub 
    
    Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
    On Error Resume Next
        If Progress = -1 Then loadbar.Value = 100
            loadinfo.Caption = "Done"
        If Progress > 0 And ProgressMax > 0 Then
           loadbar.Value = Progress * 100 / ProgressMax
           loadinfo.Caption = Int(Progress * 100 / ProgressMax) & "%"
        End If
        Exit Sub
    End Sub
    
    Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
    On Error Resume Next
    If (InStr(WebBrowser1.LocationURL, "<html>")) <> 0 Then
    urlbar.Text = ""
    else
    urlbar.Text = (WebBrowser1.LocationURL)
    end if
    End Sub
    
    Private Sub stopbutton_click()
    On Error Resume Next
    WebBrowser1.Stop
    End Sub
    
    
    Private Sub Form1_Resize()
    WebBrowser1.Width = Me.ScaleWidth
    End Sub
    WebBrowser=Webbrowser1, Text input for url = urlbar (TextBox), I also have a progress bar and label alongside. All other objects are easily identifiable.

    MY WebBrowser works well but there are a few slight problems that i am finding difficult to change.
    1. When i type in the textbox and move my mouse away from it, all content that i have just typed is deleted???
    2. When i manage to submit the url, the content of the textbox (url) dissapears and only when the page has loaded does it come back. I would like the textbox to always have content.
    3. Occasionally when i am browsing i encounter problems such as "-1 (ffffffffffff)" and "-2 (fffffffffe)" I have checked my code. How can i fix this?
    4. Additionally i would like to improve the appearance of my application by changing the user interface, is there a simple way to do this? Do i have to 'Skin'?? Please Help!!


    I know this is a long list of questions and problems, sorry if this is slightly overbearing. I just need help!
    Greatly Appreciated,
    Hardware

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: WebBrowser Problems

    Step number one: Remove, as in completely delete all On Error Resume Next statements and never use them again.

    Your program could be generating an error. If it is, you are ignoring it, and are now wondering why somethings do not work. If you have errors, let them happen. That way, you can address them and fix them.

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: WebBrowser Problems

    comment out this section... then try it.
    the status text changes constantly while load and looks like its triggering the urlbar to clear.

    Code:
    Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
    On Error Resume Next
    If (InStr(WebBrowser1.LocationURL, "<html>")) <> 0 Then
    urlbar.Text = ""
    else
    urlbar.Text = (WebBrowser1.LocationURL)
    end if
    End Sub

    read the tutorial i wrote - link in my sig


    you will want to use the Webbrowser1_DocumentComplete Event



    Code:
    Private Sub Webbrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        'The next line is important. It check to see if the ENTIRE document is loaded
        If (pDisp Is Webbrowser1.Application) Then
        urlbar.text = URL
        End If
    End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    7

    Re: WebBrowser Problems

    Ok thanks very much for all the help. I removed all the 'On error resume next' parts in the code and in response to the last reply i changed to
    Code:
    Private Sub Webbrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        'The next line is important. It check to see if the ENTIRE document is loaded
        If (pDisp Is Webbrowser1.Application) Then
        urlbar.text = URL
        End If
    End Sub
    From my previous method and it seems to work much better.

    This all seems to work well, except the back and forward buttons. If there is nothing to go forward or back to, when the button is pressed an error occurs.
    "Runtime Error:'-2147467259 (80004005)':
    Method GoBack of Object 'IeWebBrowser2' Failed" and
    "Runtime Error:'-2147467259 (80004005)':
    Method GoForward of Object 'IeWebBrowser2' Failed"

    How can i fix this?
    Also how i can i stop the urlbar (textbox) clearing itself when the mouse is moved, as mentioned in my first post??

    All your help is greatly appreciated, Thanks to all, Hardware

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: WebBrowser Problems

    as far as the back/forward buttons...(change the button names accordingly)


    I know Hack said remove all On Error Resume Next, but in this case leave it.
    Errors can occur in this and can safely be ignored. This will enable/disable the back and forward buttons.
    Code:
    Private Sub Webbrowser1_CommandStateChange(ByVal Command As Long, ByVal Enable As Boolean)
        On Error Resume Next
        DoEvents: DoEvents: DoEvents
        If Enable = True And Command = CSC_NAVIGATEBACK Then
            cmdBackButton.Enabled = True
        ElseIf Enable = False And Command = CSC_NAVIGATEBACK Then
            cmdBackButton.Enabled = False
        End If
        If Enable = True And Command = CSC_NAVIGATEFORWARD Then
            cmdFwdButton.Enabled = True
        ElseIf Enable = False And Command = CSC_NAVIGATEFORWARD Then
            cmdFwdButton.Enabled = False
        End If
    End Sub
    as far as the mouse move.. i really dont know. i dont see any mousemove code
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    7

    Re: WebBrowser Problems

    Cheers everyone especially Static you have been a great help.
    My WebBrowser is fully functional and i probably will add other features later on in the project. My next target is to improve the appearance of the user interface, i already have a selected colour scheme but i am willing to change it slightly to fit in.

    Should i use photoshop and images to achieve a better interface or shall i use 'skinning' or any other options?

    Skinning is completely new to me so if anyone could explain or tell me how and what you do to 'skin' i would be very grateful.

  7. #7
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: WebBrowser Problems

    do a search for skin.. there are examples etc..

    and read the tutorial in my sig. there are some cool things you can do.
    I have a webbrowser that works with vbfroums and highlights new posts, posts ive replied to etc. also pulls the list of whos online, the forum list show in button dropdown...
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    7

    Re: WebBrowser Problems

    ok i have done but will do more research. I've done more testing of my browser and have found a few little problems.
    1. When i browse on website and click very quickly without waiting for the page to load i encounter an error "Runtime error:'-1 (fffffff)'". I think this error is due to rushing or telling the browser to load a page when it hasn't finished the previous page. I'm not sure. Any help?
    2. Secondly, when i resize my form the WebBrowser still stays its original size and there is "cutoff" is there any way to make the browser resize to stay with the form size? I added:
      Code:
      Private Sub Form1_Resize()
      WebBrowser1.Width = Me.ScaleWidth
      End Sub


    but it doesn't seem to work? Grrrrr

    Hope you can help, thanks for everything so far. Any other features you would recomend?

    Cheers, Hardware

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: WebBrowser Problems

    Look in our CodeBank for skinning examples.

  10. #10

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    7

    Re: WebBrowser Problems

    Right. But can anyone answer my questions above? Static any help?

    Thanks everyone, Hardware

  11. #11
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: WebBrowser Problems

    that code should work for resize.

    the clicking shouldnt cause an error. when u get the error, what line does the IDE point to?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  12. #12

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    7

    Re: WebBrowser Problems

    When i get the error it gives the option of "ok" and "help" No debug option and does not highlight any code. It seems to be occuring randomly now.

    Can anyone help please?
    Last edited by hardware; Aug 14th, 2008 at 03:42 AM.

  13. #13

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    7

    Re: WebBrowser Problems

    Please? lol. I have searched high and low.

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

    Re: WebBrowser Problems

    Question #1 - Have no idea

    Question #2 - There is no way the WebBrowser can stays at it's original size when you resize your Form and what does "cutoff" mean?

    Maybe you should post the pertinent part of your code so someone can run a quick test on it. Include only the code that has the WebBrowser control, the code that navigates to a Website, the Form_Load and the Form_Resize. Run this code and if it still does what you are saying in your post #8 then post that code here. I mean, if possible, post a zip file of the project.

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