我可以强制VBA在“空”与“零”之间区别对待变体arg吗?

时间:2019-03-17 17:05:05

标签: vba

鉴于Empty = 0的变体,正在寻找是否有人可以区分两者,就像下面的虚拟函数一样

Function doGetFmt(v As Variant) As String
    dim s as String
    If IsEmpty(v) Then s ="Empty"
    If v=0 s= "zero"
    doGetFmt = s
End Function

1 个答案:

答案 0 :(得分:0)

根据GSerg的评论:

Dim v As Variant

Debug.Print IsEmpty(v) '>> #true#
Debug.Print v = 0      '>> true

v = 0

Debug.Print IsEmpty(v) '>> #false#
Debug.Print v = 0      '>> true

如果IsEmpty()返回false时仅测试零,那么您将更接近所需的内容。