【问题标题】:vb.net progress bar is not valid for 'Value'. 'Value' should be between 'minimum' and 'maximum'vb.net 进度条对“值”无效。 “值”应介于“最小值”和“最大值”之间
【发布时间】:2013-07-16 14:23:58
【问题描述】:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    If ProgressBar2.Value = 100 Then
        ProgressBar2.Value = ProgressBar2.Maximum()
        MsgBox("Posting Completed!")
        ProgressBar2.Enabled = False
    Else
        Do
            ProgressBar2.Value += 5
        Loop
    End If


End Sub

我已经花了 3 个小时来找出问题所在,但直到现在我仍然找不到解决方案,在我运行它之前没有错误,它给了我这个错误

“105”的值对“值”无效。 “值”应介于“最小值”和“最大值”之间。 参数名称:值

我已经设置好了

ProgressBar2.Minimum = 0
ProgressBar2.Maximum = 100

请帮帮我:(

【问题讨论】:

    标签: vb.net visual-studio loops progress-bar max


    【解决方案1】:

    上面的代码有问题。

    循环

        Do
            ProgressBar2.Value += 5
        Loop
    

    永远不会停止,当它达到 100 时,它会增加超过最大值。
    不,当你在这个循环中时,方法入口处的测试不会被执行

    您应该只增加一次,然后退出循环并等待下一个 Timer 滴答声再次增加

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If ProgressBar2.Value + 5 >= ProgressBar2.Maximum Then
            ProgressBar2.Value = ProgressBar2.Maximum
            MsgBox("Posting Completed!")
            Timer1.Stop()
        Else
            ProgressBar2.Value += 5
        End If
    End Sub
    

    另外,当你达到最大值时,你应该简单地停止 Timer1 而不是禁用 ProgressBar2

    【讨论】:

    • 这就是问题所在,不错!
    【解决方案2】:

    因为您将值从 100 增加到 105,所以它在 If 语句中失败,因为您没有检查它是否大于或等于 >=。

    此外,您可以摆脱循环,因为它没有出口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-28
      • 1970-01-01
      • 2011-12-04
      • 1970-01-01
      • 2022-07-18
      相关资源
      最近更新 更多