option explicit class clsList private a__(),b__(),c__ public property get AllowDuplicates AllowDuplicates=c__ end property public property let AllowDuplicates(AValue) c__=AValue end property private sub class_initialize redim a__(0) c__=true end sub private sub class_terminate redim a__(0) end sub public function Count Count=UBound(a__) end function public function Add(AObject) dim d__ d__=true if not AllowDuplicates then d__ = not(IndexOf(AObject) > 0) if d__ then dim e__ e__=Count + 1 redim preserve a__(e__) set a__(e__)=AObject end if end function public sub Clear redim a__(0) redim b__(0) end sub public function FindInstanceOf(ATypeName, AStartAt) dim li,d__ FindInstanceOf=0 d__=AStartAt if (d__ = 0) then d__ = 1 if (d__ <= Count) then for li = d__ to Count if StringsEqual(TypeName(Item(li)), ATypeName) then FindInstanceOf = li exit for end if next end if end function public function First if Count > 0 then set First = Item(1) :else: set First = nothing end function public function IndexOf(AObject) dim li,d__ d__=0 if Count > 0 then for li = 1 to Count if AObject is Item(li) then d__ = li exit for end if next end if IndexOf=d__ end function public function Item(Index) if (Index > 0) and (Index <= Count) then set Item = a__(Index) :else: set Item = nothing end function public function Last if Count > 0 then set Last = Item(Count) :else: set Last = nothing end function public function Remove(AObject) dim d__ d__=IndexOf(AObject) if d__ > 0 then RemoveByIndex(d__) end function public function RemoveByIndex(Index) redim b__(UBound(a__)-1) dim li, lj lj=1 if Count > 0 then for li = 1 to Count if li <> Index then set b__(lj) = a__(li) lj=lj + 1 end if next if UBound(b__) >= 0 then redim a__(UBound(b__)) for li=1 to UBound(b__) set a__(li)=b__(li) next end if end if end function public function Replace(Index, AObject) set a__(Index)=AObject end function public sub Swap(IndexA, IndexB) dim d__,e__ set d__=a__(IndexA) set e__=a__(IndexB) Replace IndexA, e__ Replace IndexB, d__ set d__=nothing set e__=nothing end sub end class