1
Dim name As String: name = "NaN"
' Doesn't generate an error:
If IsNumeric(name) Then
Dim iv As Integer: iv = CInt(name)
If iv > 0 Then
' Do something
End If
End If
' Does generate error 13 on 'CInt(name)': Types don't match
If IsNumeric(name) And CInt(name) > 0 Then
' Do something
End If
爲什麼第二個條件CInt(name) > 0
即使單if語句評價?或者這正是VBA所做的事情?我習慣於編寫沒有這種行爲的C#代碼。
請參閱[vba短路邏輯](http://stackoverflow.com/questions/7015471/does-the-vba-and-operator-evaluate-the-second-argument-when-the-first-is-false ) – amdixon