【发布时间】:2022-01-12 04:23:24
【问题描述】:
我在 Visual Studio 2019 上使用 Visual Basic。即使第一个“if”或其中一个前身为真,是否有一种方法可以执行所有 ElseIf 块?如果 ElseIf 无法使用,我还能使用其他命令吗?最后的想法和解释为什么我不能只做分隔 Ifs 是因为如果所有语句都是错误的,我需要给出错误消息,并且我不知道如何在没有 ElseIf 命令的情况下对它们进行分组,所以这是我现在唯一的想法就是这样做。
所以,这就是 ElseIf 结构,当它发现其中一个语句为真时它会停止
If(boolean_expression 1)Then
' Executes when the boolean expression 1 is true
ElseIf( boolean_expression 2)Then
' Executes when the boolean expression 2 is true
ElseIf( boolean_expression 3)Then
' Executes when the boolean expression 3 is true
Else
' executes when the none of the above condition is true
End If
所以,我想执行每一个 ElseIf,不管前任是真还是假。希望您能帮我解决这个问题,谢谢!
【问题讨论】:
-
您仍然可以使用单独的 ifs。如果 if 语句为真(结果 += 1),只需将递增值存储到变量中。然后在最后评估变量的值。如果结果 = 4(或您做了多少条件),则显示您的消息
标签: vb.net visual-studio if-statement