检查空字符串
Check an empty string
我正在尝试检查 lotusscript 代理中的变体是否为空,因为它是逻辑条件的一部分,但是当我尝试 运行 时出现错误状态
Object variable not set
关于下面的代码行:
If CStr(contractId(0)) <> "" Then
我试过了
If IsNull(CStr(contractId(0))) Then
但这也不管用。为什么这行不通?
您似乎在尝试使用 shorthand 符号来访问名为 ContractID 的项目,但在某些情况下,文档中不存在该项目。 (我猜我们在这里看不到实际的文档参考,因为您使用的是 with
语句。)
在尝试访问 ContractID(0) 之前让您的代码调用 NotesDocument.hasItem("ContractID")。即,
If doc.hasItem("ContractID") then
If CStr(contractId(0)) <> "" Then
变体 "emptiness" 的检查使用以下方法完成:
If Not IsEmpty( contractID ) then
'- do your stuff
End If
如果您使用 GetItemValue() 填充 contractID,那么您必须编写自己的 isempty 版本,如果所有元素都是空字符串,则认为变体为空。以下函数检查变体是否真的为空,甚至可以将字符串作为输入。
Function IsVariantEmpty (varValues As Variant) As Boolean
IsVariantEmpty = True
If Isempty (varValues) Then
Exit Function
End If
If Isscalar (varValues) Then
If Trim$ (Cstr (varValues)) <> "" Then
IsVariantEmpty = False
End If
Exit Function
End If
Forall value In varValues
If Trim$ (Cstr (value)) <> "" Then
IsVariantEmpty = False
Exit Function
End If
End Forall
End Function
我正在尝试检查 lotusscript 代理中的变体是否为空,因为它是逻辑条件的一部分,但是当我尝试 运行 时出现错误状态
Object variable not set
关于下面的代码行:
If CStr(contractId(0)) <> "" Then
我试过了
If IsNull(CStr(contractId(0))) Then
但这也不管用。为什么这行不通?
您似乎在尝试使用 shorthand 符号来访问名为 ContractID 的项目,但在某些情况下,文档中不存在该项目。 (我猜我们在这里看不到实际的文档参考,因为您使用的是 with
语句。)
在尝试访问 ContractID(0) 之前让您的代码调用 NotesDocument.hasItem("ContractID")。即,
If doc.hasItem("ContractID") then
If CStr(contractId(0)) <> "" Then
变体 "emptiness" 的检查使用以下方法完成:
If Not IsEmpty( contractID ) then
'- do your stuff
End If
如果您使用 GetItemValue() 填充 contractID,那么您必须编写自己的 isempty 版本,如果所有元素都是空字符串,则认为变体为空。以下函数检查变体是否真的为空,甚至可以将字符串作为输入。
Function IsVariantEmpty (varValues As Variant) As Boolean
IsVariantEmpty = True
If Isempty (varValues) Then
Exit Function
End If
If Isscalar (varValues) Then
If Trim$ (Cstr (varValues)) <> "" Then
IsVariantEmpty = False
End If
Exit Function
End If
Forall value In varValues
If Trim$ (Cstr (value)) <> "" Then
IsVariantEmpty = False
Exit Function
End If
End Forall
End Function