Wednesday, February 11, 2009

how we can check LIST for empty

Today I was faced with small issue, I realised that I don't know how to check LIST variable for empty. Really, I was so confused. I've done it using next approach, but to be honest I don't like it. If anybody knows better approch, please share it here!
...
isValid = False
Forall x In myList
isValid = True
Exit Forall
End Forall
...

2 comments:

  1. Anonymous7:35 AM

    Hi!

    Try this link...the best explanation abouts LISTS...

    Yours,
    René

    http://www.billbuchan.com/newweb.nsf/b41aea976eaaa95980256cc7000e0114/220ff41ed212eeca80256cc7000f679f!OpenDocument

    ReplyDelete
  2. Hi Dmytro,

    Sometimes it could be useful to wrap your list processing is some class.

    Class MyList
    Private m_list List As Variant
    Private m_count As Double

    Sub New
    End Sub

    Public Property Set List(tag As Variant) As Variant
    If Not Iselement(m_list(tag)) Then
    m_count = m_count + 1
    End If
    If Isobject(Me.List) Then
    Set m_list(tag) = Me.List
    Else
    m_list(tag) = Me.List
    End If
    End Property

    Public Property Get List(tag As Variant) As Variant
    If Isobject(Me.List) Then
    Set Me.List = m_list(tag)
    Else
    Me.List = m_list(tag)
    End If
    End Property

    Public Property Get ListValues As Variant
    Me.ListValues = m_list
    End Property

    Public Function IsEmpty As Boolean
    If Me.Count = 0 Then
    Me.IsEmpty = True
    End If
    End Function

    Public Function Erase(tag As Variant) As Boolean
    If Iselement(m_list(tag)) Then
    Erase m_list(tag)
    m_count = m_count - 1
    End If
    End Function

    Property Get Count As Double
    Count = m_count
    End Property
    End Class

    Sample usage:

    Sub Initialize
    Dim my_list As New MyList
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Dim v As String

    Set db = s.CurrentDatabase
    v = "345241234"
    Set my_list.List(1) = s
    Set my_list.List(2) = db
    my_list.List(1) = v
    If Not my_list.IsEmpty Then
    Messagebox my_list.Count
    End If

    Forall o In my_list.ListValues
    Messagebox 1
    End Forall

    Call my_list.Erase(2)
    If Not my_list.IsEmpty Then
    Messagebox my_list.Count
    End If

    Call my_list.Erase(1)
    If my_list.IsEmpty Then
    Messagebox "Empty :-)"
    End If
    End Sub

    Cheers,
    Bogdan.

    ReplyDelete