有人可以幫我理解爲什麼If/Then/End If工作但是IIf不工作?爲什麼IIf不能像If/Then/EndIf一樣工作?
我跑我的代碼這一點,它按預期工作:
For Each BtnObj In Padre.Controls
With BtnObj
If nullinator(.Tag) = 0 Then
.Visible = False
Else
.Visible = True
End If
End With
Next
這裏是我的 「nullinator」 功能:
Public Shared Function nullinator(ByVal CheckVal As String) As Integer
' Receives a string and returns an integer (zero if Null or Empty or original value)
If String.IsNullOrEmpty(CheckVal) Then
Return 0
Else
Return CheckVal
End If
End Function
不過,如果我使用此代碼,nullinator(運行它。 Tag)= 0即使Tag屬性的內容爲空,也總是等於False。這裏的代碼:
For Each BtnObj In Padre.Controls
With BtnObj
IIf(nullinator(.Tag) = 0, .Visible = False, .Visible = True)
End With
Next
哦,是的,「Padre」變量是容器(父)對象。
爲什麼我沒有成功使用IIf的任何見解將不勝感激!
當你的函數sig需要一個Integer時返回一個字符串不是一個好主意。 –
可能的解決方案https://stackoverflow.com/questions/28377/performance-difference-between-iif-and-if,這些答案中的所有內容都會添加一種或另一種形式的差異...無需再添加一個圖書。 – Codexer