[英]VBA If, elseif statement, how to set a constant when the first IF statement is not met
我有一个If,Elseif,Else语句。 如果满足第一个If,我想插入径流和渗滤的计算值。 但是,如果不满足第一个IF条件,径流和渗滤将始终被分配为0。 我在下面粘贴了我的代码。 我遇到的问题是,如果在第一个IF语句后设置percolation并且runoff = 0,则我的打印子项将始终打印0,而不是计算出的值。 如果不满足第一个IF条件,如何将径流和渗滤分配为常量? 我知道我可以在每个后续条件中分配runoff = 0,percolation = 0,但是我正在尝试减少代码的体积。
Do
If (fc - WC(j - 1) + RefET(i)) <= Precip(i) Then
WC(j) = fc
WCinit(j) = WC(j)
Runoff(j - 1) = (Precip(i) - (fc - WC(j - 1) + RefET(i))) * 0.5
Percolation(j - 1) = (Precip(i) - (fc - WC(j - 1) + RefET(i))) * 0.5
' Runoff(j - 1) = 0 <-If I assign these here, it "overrides" the value I calculated on the previous line. I want to reduce the bulkiness of my code by assigning these values if the first IF condition is not met
' Percolation(j - 1) = 0
ElseIf (WC(j - 1) + Precip(i) - RefET(i)) > pwp Then
WC(j) = WC(j - 1) + Precip(i) - RefET(i)
WCinit(j) = WC(j)
Runoff(j - 1) = 0
Percolation(j - 1) = 0
Else
WC(j) = pwp
WCinit(j) = WC(j)
Runoff(j - 1) = 0
Percolation(j - 1) = 0
End If
j = j + 1
i = i + 1
Loop While j < 14
或在将它们制成尺寸时。 Dim渗滤为int = 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.