我正在使用RequisitePro40和Word 2010中的VBA 7.0。在我的一个模块中,我有以下循环和If条件:
Dim rqRequirements As ReqPro40.Requirements
Dim rqRequirement As ReqPro40.Requirement
Const eAttrValueLookup_Label = 4
Dim a As Integer
...
For Each vReqKey In rqRequirements
Set rqRequirement = rqRequirements(vReqKey)
If rqRequirement.AttrValue("MyAttreName", eAttrValueLookup_Label).text <> Null Then
a = 1
End If
If rqRequirement.AttrValue("MyAttreName", eAttrValueLookup_Label).text = Null Then
a = 2
End If
Next
在循环的每次迭代中,都会执行a = 1和a = 2两个语句。
根据这里所述,等于和不等于运算符分别是"="和"<>"。因此,我预期字符串中要么执行a = 1,要么执行a = 2。我的语法有问题吗?还是与ReqPro相关的问题?
我也尝试使用"Is"和"IsNot"运算符,但结果是编译器错误:类型不匹配。
有人能帮我解决这个问题吗?
更新:实际目标是查看
是否为空。我添加了第二个if来显示该语句似乎没有按照我的预期工作的问题。rqRequirement.AttrValue("MyAttreName", eAttrValueLookup_Label).text
将"Null"替换为"vbNullString"没有任何改变。
我也尝试了@Slai建议的IsNull函数,结果基本相同:
If IsNull(rqRequirement.AttrValue(att, eAttrValueLookup_Label).text) Then
a = 3
End If
If Not IsNull(rqRequirement.AttrValue(att, eAttrValueLookup_Label).text) Then
a = 4
End If
语句a=3和a=4都是真的且被执行。
rqRequirement.AttrValue("MyAttreName", eAttrValueLookup_Label).text
返回的对象类型是什么?(您可以查看 ReqPro40 对象模型文档来了解)Len(stringVariable)>0
。如果strVariable = ""
也是可能的,但执行效率不如前者高。 - Cindy Meister.text
可能是问题所在。答案建议使用.value
代替。 - IQV