gpt4 book ai didi

vba - If 语句 VBA ACCESS 2010

转载 作者:行者123 更新时间:2023-12-03 00:13:19 25 4
gpt4 key购买 nike

使用时

If Then
'Do Something
Else If
'Do Something
End If

如果第一个和第二个条件为真,它会只执行第一个条件还是两个都执行?

出于某种原因,当我有此代码时:

Dim Report As String

If (DateRange_Pro_TotalCount > 0) Then

Dim DateRange_Pro_ReportStr As String

DateRange_Pro_ReportStr = "Total Referrals: " & DateRange_Pro_TotalCount & vbNewLine _

Report = Report & DateRange_Pro_ReportStr

ElseIf (DateRange_InPro_TotalCount > 0) Then

Dim DateRange_InPro_ReportStr As String

DateRange_InPro_ReportStr = "Total Referrals: " & DateRange_InPro_TotalCount & vbNewLine _

Report = Report & DateRange_InPro_ReportStr

End If

'next statement prints report variable to textBox

即使两个条件都为真,该语句也仅执行第一个条件。我将“Else If”更改为“End If”和“If”(两个不同的条件语句,而不是一个具有两个条件的语句)并且它起作用了。

最佳答案

是的,你是对的,它只会执行第一个 block

来自IF-THEN-ELSE Statement (VBA)

If condition_1 Then
result_1

ElseIf condition_2 Then
result_2
...
ElseIf condition_n Then
result_n

Else
result_else

End If

condition_1 to condition_n are evaluated in the order listed. Once a condition is found to be true, the IF-THEN-ELSE statement will execute the corresponding code and not evaluate the conditions any further.

result_1 to result_n is the code that is executed once a condition is found to be true.

关于vba - If 语句 VBA ACCESS 2010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12667632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com