dcsimg
Results 1 to 5 of 5

Thread: [RESOLVED] WebBrowser1 ProgressChanged Negative Value problem

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,569

    Resolved [RESOLVED] WebBrowser1 ProgressChanged Negative Value problem

    I'm trying to get my progressbar's value to reflect the e.CurrentProgress in a webbrowser's Progress changed and I'm running into some problems.
    Code:
    Private Sub WebBrowser1_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
            progressStatusBar.Maximum = CInt(e.MaximumProgress)
            progressStatusBar.Value = CInt(e.CurrentProgress)
        End Sub
    My problem happens when I try to set the progress bar's value. It throws an error saying "Value of '-1' is not valid for 'Value'. 'Value' should be between 'minimum' and 'maximum'." however, if I set up a breakpoint on the two lines, it tells me that the maximum is 10,000 and the value is 100. So I'm kinda confused on how to fix this. Any suggestions is appreciated.

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,292

    Re: WebBrowser1 ProgressChanged Negative Value problem

    I don't know where exactly the problem is since you didn't provide enough info, but you can work around that issue simply by testing the value of e.CurrentProgress to make sure that it's positive before assigning it to the progressbar.value.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,569

    Re: WebBrowser1 ProgressChanged Negative Value problem

    What's crazy is if I change the code to:
    Code:
    Private Sub WebBrowser1_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
            progressStatusBar.Maximum = CInt(e.MaximumProgress)
            TextBox4.Text = TextBox4.Text & Environment.NewLine & e.CurrentProgress.ToString
        End Sub
    The textbox's output is:
    100
    100
    70100
    1000000
    -1
    1000000
    0
    So it does look as though a negative value is being thrown, but after it happens after it reaches the maximum. So how would I prevent that negative value being thrown? If I try to wrap the code in an if/then statement, like if e.currentprogress > 0 then..., then the progressbar's value doesn't change at all.

    Edit - Even if I try this:
    Code:
    progressStatusBar.Maximum = CInt(e.MaximumProgress + 1)
            progressStatusBar.Value = CInt(e.CurrentProgress + 1)
            If progressStatusBar.Value = progressStatusBar.Maximum Then
                progressStatusBar.Value = progressStatusBar.Minimum
            End If
    it wouldn't work because for some reason the value the current progress does reach the maximum before the document is completed.
    Last edited by dday9; Jul 13th, 2012 at 10:24 AM.

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,292

    Re: WebBrowser1 ProgressChanged Negative Value problem

    This is what I meant:
    Code:
    Private Sub WebBrowser1_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
            progressStatusBar.Maximum = 100
            Dim current as Long = e.CurrentProgress
            Dim max As Long = e.MaximumProgress
            If current > 0 AndAlso max > 0 Then
                 progressStatusBar.Value = CInt((current / max) * 100)
            End If
    End Sub
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,569

    Re: WebBrowser1 ProgressChanged Negative Value problem

    Ahh, ok. Thanks stanv, works like a charm.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width