For example:
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
Why is the second condition CInt(name) > 0
even evaluated with the single if statement? Or is this just what VBA does? I'm used to write C# code which doesn't have this kind of behavior.
Or is this just what VBA does?
Yes.
Use this instead:
If IsNumeric(name) Then
If CInt(name) > 0 Then
' Do something
End If
End If
or any other method from the post linked by amdixon.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments