Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Code for a progress bar in a Web Browser needed.

DprogusaDprogusa Posts: 4Member
I've written a Web Browser using VB6. I'm only an intermediate
level VB programmer. Using Steven Holzner's VB6 Black Book I've
managed to incorporate a Status Bar that displays text when a
dowmload begins and completes. Now I'd like to add a Progress Bar. Mr. Holzner tells what it is and doe's, but there is no code. THANKS.

Comments

  • JomacJomac Posts: 231Member
    : I've written a Web Browser using VB6. I'm only an intermediate
    : level VB programmer. Using Steven Holzner's VB6 Black Book I've
    : managed to incorporate a Status Bar that displays text when a
    : dowmload begins and completes. Now I'd like to add a Progress Bar. Mr. Holzner tells what it is and doe's, but there is no code. THANKS.
    :

    OK asuming that the WebBrowser AX Control is caller 'wbrWin' and the Progress Bar AX control is called 'prgProg' use the following code.

    [code]
    Private Sub wbrWin_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
    On Local Error Resume Next
    prgProg.Min = 0
    prgProg.Max = ProgressMax + 1
    prgProg.Value= Progress
    End Sub
    [/code]

    ALl the rest will take care of it self.
    Regards Jomac


  • JomacJomac Posts: 231Member
    As a side note.

    If you need to know where to find the Progress Bar AX Control. It is part of the 'Windows Common Controls' set.

    Regards Again, Jomac

  • DprogusaDprogusa Posts: 4Member
    : As a side note.
    :
    : If you need to know where to find the Progress Bar AX Control. It is part of the 'Windows Common Controls' set.
    :
    : Regards Again, Jomac
    :
    HI, Jomac
    Thanks for responding to my message. I think showing you a code SEGMENT
    where I'm using the progress bar might clarify my problem and I really
    hope you can direct me to solve it. I allready have the bar positioned
    below the web browser.

    Private Sub Form_Load()
    WebBrowser1.Navigate "www.netscape.com"
    Combo1.Text = "www.netscape.com" 'display web address
    Combo1.AddItem Combo1.Text 'add address to list
    Timer1.Enabled = False 'used to move bar
    End Sub

    Private Sub WebBrowser1_DownloadBegin()
    ProgressBar1.Value = 0 'bar is empty
    Label2.Caption = "Getting Page...." 'status bar message
    Timer1.Enabled = True 'start bar moving
    End Sub

    Private Sub Timer1_Timer()
    'progress bar's MAX value is set at 300

    ProgressBar1.Value = ProgressBar1.Value + 2 'any value higher than
    '2 the bar moves to fast
    End Sub

    Private Sub WebBrowser1_DownloadComplete()
    Me.Caption = WebBrowser1.LocationName
    Label2.Caption = "Done" 'status bar message
    Timer1.Enabled = False 'stop bar
    ProgressBar1.Value = 0 'reset bar to empty
    End Sub

    Now for the problem. The download time varies as you well know. The time
    it takes for the progress bar to fill up depends on it's MAX value prop-
    perty setting which relates to the timers INTERVAL property setting. If
    for example the MAX value of the progress bar is set at 100 and the Timer
    INTERVAL setting is 1000 it will take 10 seconds for the bar to fill up.
    I've tried values that allow 1 1/2 minutes of download time. Now if the
    download completes in less time the progress bar works but doesn't fill
    up (of course). This is somewhat acceptable. However it should be full
    to show download is complete and also correspond to the status bar msg.
    If the download time exceeds 1 1/2 minutes the timer completes,the prog-
    ress bar is full and the browser program terminates in a run-time error.
    I've tried a few conditional statements, but my logic must be wrong be-
    cause they have no effect.
    I want to thank you in advance for your time. I hope you have a solution.

    Thanks again, Dprogusa

  • JomacJomac Posts: 231Member
    I can sorta see what you are trying to do. What I can't see is why.
    It seems you are trying to re-invent a wheel that is not that easy to re-invent...

    Detecting the Download progess is hard because of the fluctuations in bandwidth ect. Thankfully we do not have to worry about writing exessive lines of code to show the progress, because the WebBrowser Control works it out for us (as best it can).

    When the 'ProgressChange' event occurs in a WebBrowser control it gives us all the information you need to fully run a ProgressBar Control.

    The 'ProgressMax' property is dynamic and changes each time the event occurs.
    The 'Progress' property represents the part of 'ProgressMax' that is complete.

    When the download completes the 'Progress' property will equal either -1 or 0.

    [blue][code]
    Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
    On Local Error Resume Next
    ProgressBar1.Min = 0
    ProgressBar1.Max = ProgressMax + 1
    ProgressBar1.Value= Progress
    End Sub
    [/code][/blue]

    Set the Status bar text the same way you have been. Or for simplicity, set it on the WebBrowser's 'StatusTextChange' event.
    After all VB is an 'Event-Driven Language'.

    I hope this can help you out, if you are trying to do more than just show the download progress for the WebBrowser then let me know what and i will be happy to look at ways of doing it.


    ______
    [size=2][b][blue]J[/blue]omac.[/b][/size]


  • DprogusaDprogusa Posts: 4Member
    : I can sorta see what you are trying to do. What I can't see is why.
    : It seems you are trying to re-invent a wheel that is not that easy to re-invent...
    :
    : Detecting the Download progess is hard because of the fluctuations in bandwidth ect. Thankfully we do not have to worry about writing exessive lines of code to show the progress, because the WebBrowser Control works it out for us (as best it can).
    :
    : When the 'ProgressChange' event occurs in a WebBrowser control it gives us all the information you need to fully run a ProgressBar Control.
    :
    : The 'ProgressMax' property is dynamic and changes each time the event occurs.
    : The 'Progress' property represents the part of 'ProgressMax' that is complete.
    :
    : When the download completes the 'Progress' property will equal either -1 or 0.
    :
    : [blue][code]
    : Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
    : On Local Error Resume Next
    : ProgressBar1.Min = 0
    : ProgressBar1.Max = ProgressMax + 1
    : ProgressBar1.Value= Progress
    : End Sub
    : [/code][/blue]
    :
    : Set the Status bar text the same way you have been. Or for simplicity, set it on the WebBrowser's 'StatusTextChange' event.
    : After all VB is an 'Event-Driven Language'.
    :
    : I hope this can help you out, if you are trying to do more than just show the download progress for the WebBrowser then let me know what and i will be happy to look at ways of doing it.
    :
    :
    : ______
    : [size=2][b][blue]J[/blue]omac.[/b][/size]
    :
    :
    :Jomac,
    :Thats what I've been looking for. I've looked everywhere in the resourses that I have for the code to put in ProgressChange(). This why I wrote the
    :code you saw.
    :
    :Thank you, Dprogusa

  • JomacJomac Posts: 231Member
    : : I can sorta see what you are trying to do. What I can't see is why.
    : : It seems you are trying to re-invent a wheel that is not that easy to re-invent...
    : :
    : : Detecting the Download progess is hard because of the fluctuations in bandwidth ect. Thankfully we do not have to worry about writing exessive lines of code to show the progress, because the WebBrowser Control works it out for us (as best it can).
    : :
    : : When the 'ProgressChange' event occurs in a WebBrowser control it gives us all the information you need to fully run a ProgressBar Control.
    : :
    : : The 'ProgressMax' property is dynamic and changes each time the event occurs.
    : : The 'Progress' property represents the part of 'ProgressMax' that is complete.
    : :
    : : When the download completes the 'Progress' property will equal either -1 or 0.
    : :
    : : [blue][code]
    : : Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
    : : On Local Error Resume Next
    : : ProgressBar1.Min = 0
    : : ProgressBar1.Max = ProgressMax + 1
    : : ProgressBar1.Value= Progress
    : : End Sub
    : : [/code][/blue]
    : :
    : : Set the Status bar text the same way you have been. Or for simplicity, set it on the WebBrowser's 'StatusTextChange' event.
    : : After all VB is an 'Event-Driven Language'.
    : :
    : : I hope this can help you out, if you are trying to do more than just show the download progress for the WebBrowser then let me know what and i will be happy to look at ways of doing it.
    : :
    : :
    : : ______
    : : [size=2][b][blue]J[/blue]omac.[/b][/size]
    : :
    : :
    : :Jomac,
    : :Thats what I've been looking for. I've looked everywhere in the resourses that I have for the code to put in ProgressChange(). This why I wrote the
    : :code you saw.
    : :
    : :Thank you, Dprogusa
    :

    My Pleasure, there are a lot of people out there writing huge programs that could be cut in half if only for an understanding of the VB/AX shortcuts. Best of luck...


    ______
    [size=2][b][blue]J[/blue]omac.[/b][/size]


Sign In or Register to comment.