AJF
AJF

Reputation: 1931

Check an empty string

I am trying to check if a variant is empty in a lotusscript agent as it is part of the logic condition but when I attempt to run an error states

Object variable not set

about the line of code below:

If CStr(contractId(0)) <> "" Then

I have tried

If IsNull(CStr(contractId(0))) Then

But that does not work either. Why won't this work?

Upvotes: 0

Views: 4093

Answers (2)

Tode
Tode

Reputation: 12080

The check for the "emptiness" of a variant is done using:

If Not IsEmpty( contractID ) then
  '- do your stuff
End If

If you fill contractID using a GetItemValue() then you have to write your own version of isempty, that considers a variant to be empty if all of the elements are empty strings. The following function checks, if a variant is REALLY empty, and even works for a string as input.

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

Upvotes: 2

Richard Schwartz
Richard Schwartz

Reputation: 14628

It looks like you are trying to use the shorthand notation to access an item called ContractID, but in some cases that itemd doesn't exist in the document. (I'm guessing we don't see the actual document reference here becuase you're using a with statement.)

Have your code call NotesDocument.hasItem("ContractID") before trying to access ContractID(0). I.e.,

If doc.hasItem("ContractID") then
  If CStr(contractId(0)) <> "" Then

Upvotes: 0

Related Questions