Ken Patton - 2007-11-29

Logged In: YES
user_id=1948095
Originator: NO

The problem is that the progress bar MaxValue property is an int32. In the ShowDetails sub within Form1, the following line is the source of the error.

If BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal < 100000000000 Then frmInfo.ProgressBar1.Maximum = BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal

Instead of a hard-coded 100000000000, it should check for System.Int32.MaxValue like

If BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal < System.Int32.MaxValue Then frmInfo.ProgressBar1.Maximum = BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal

Fixing this only shifts the error a couple of lines. Inside the next If statement is
frmInfo.ProgressBar1.Value = BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTransferred
If BytesTotal >= System.Int32.MaxValue, the MaxValue on the progress bar may still be 100. Setting the Value property to anything above that will cause another exception.

Since the actual Value and MaxValue are not accessible to the user, restructuring the If statement to leave the MaxValue at 100 and calculating the Value as a percent, which is done already for the Text property, is a quick fix which worked for me.

Hence, this block:

If BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal < 100000000000 Then frmInfo.ProgressBar1.Maximum = BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal

If BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal > 0 Then
frmInfo.txtPercent.Text = Mid(BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTransferred / BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal * 100, 1, 4) & " %"
frmInfo.ProgressBar1.Value = BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTransferred

End If

Becomes:
If BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal > 0 Then
frmInfo.txtPercent.Text = Mid(BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTransferred / BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal * 100, 1, 4) & " %"
frmInfo.ProgressBar1.Maximum = 100
frmInfo.ProgressBar1.Value = BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTransferred / BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal * 100
End If