user3677169
user3677169

Reputation:

isEmpty doesn't work

I have an user interface in which there is a "from-to" list. When I test it, I let the list empty, I don't insert any data in it.

But when calling isEmpty, it returns that it is not empty which is wrong.

This is my code snippet:

 Dim oFromToList As Object
   Dim vList As Variant

   Set oParameters = SmartContext.Parameters 
   If oParameters.Contains("smartFromToList1") Then   
        Set oFromToList = oParameters.Item("smartFromToList1")
        vList = oFromToList.GetList
        If Not IsEmpty(vlist) Then
        MsgBox "not empty"
        Else
        MsgBox "empty"
        end if
   End If

The name of the list is smartFromToList1, it is empty but the messages shown is "not empty"

Upvotes: 1

Views: 418

Answers (2)

jac
jac

Reputation: 9726

You're mis-using the IsEmpty function. It is used to check that a variant type variable has been initialized. Meaning whether or not the variable has been assigned a value. It cannot be used to check an object.

The line vList = oFromToList.GetList initializes the vList. It assigns what ever is returned by GetList to vList.

You do not say what kind of object oFromToList is so we can't tell you how to do your test. Depending on what GetList actually returns there may be a Count property you can check, or possibly test

vList Is Nothing
.

Upvotes: 2

Marc
Marc

Reputation: 993

IsEmpty just checks if a variable is initialized. You just Dim vList as a Variant so I'm not sure what data you are expecting in it. If it's meant to be some kind of array, list, collection, etc. then it's possible that vList is initialized but doesn't contain any items. What type of object is it? Are you able to do anything like If vList.Count > 0 Then?

Upvotes: 0

Related Questions