我正在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,不管前任是真還是假。希望你能幫我解決這個問題,謝謝!
uj5u.com熱心網友回復:
您可以單獨執行每個塊并仍然檢查是否全部為假:
If (expression1) Then 'Do Stuff
If (expression2) Then 'Do Stuff
If (expression3) Then 'Do Stuff
If Not (expression1) AndAlso Not (expression2) AndAlso Not (expression3) Then 'Do Stuff
uj5u.com熱心網友回復:
我認為在您的情況下,這樣做可能更優雅且計算速度更快:
If Not booleanExpr1 AndAlso Not booleanExpr2 AndAlso Not booleanExpr3 Then
'Fire Error Message
Else
'Execute all 3 expressions
End If
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/376239.html
