【问题标题】:How to do greater than X and less than Y in VB?VB中大于X小于Y怎么办?
【发布时间】:2012-09-28 03:48:37
【问题描述】:

这是我尝试过的……我认为这是完全错误的,因为它不起作用。

If ProgressBar1.Value > 5 < 20 Then
    Label8.Text = "Hello"
End If

非常感谢所有帮助!谢谢。

【问题讨论】:

    标签: vb.net visual-studio visual-studio-2012


    【解决方案1】:
    If ProgressBar1.Value > 5 AndAlso ProgressBar1.Value < 20 Then
        Label8.Text = "Hello"
    End If
    

    是一种方式。

    AndAlso 表示如果第一个值评估为假,则条件将“短路”。因此,如果 ProgressBar1.Value 不 > 5 - 它不会检查其余的条件。

    您也可以使用And 编写它

    If ProgressBar1.Value > 5 And ProgressBar1.Value < 20 Then
        Label8.Text = "Hello"
    End If
    

    它会评估这两个条件。在这种特殊情况下,它不会有太大区别,但我通常更喜欢 AndAlso/OrElse 而不是 And/Or

    【讨论】:

      【解决方案2】:

      您必须使用“与”行来执行与语句。它应该看起来像这样

      If ProgressBar1.Value > 5 And ProgressBar1.Value < 20 Then
          Label8.Text = "Hello"
      End If
      

      此外,如果您只希望其中一个为真,您可以使用“或”语句。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-02
        • 2023-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多