Clear method and collection 
Author Message
 Clear method and collection

Hi all,

I have created a class collection with a custom key (ex : "120B1")
 and I want to add a "clear" method .

I have writen this code :

public sub Clear()
'-------------------------------------------
dim tmpelem as cElem

For each elem in MyCollection
    Mycollection.remove elem.Idelem
Next
'-------------------------------------------
end Sub

But it's not a good way .

Can anyone help me to write this method ?

Thanks by advance

Jean-Yves RANCUREL



Mon, 29 Nov 2004 21:39:16 GMT  
 Clear method and collection
Hi Jean-Yves

In this case I always do it like this:

Public Sub Clear()
  For I = MyCollection.Count To 1 Step -1
    MyCollection.Remove I
  Next
End Sub

Regards
Andreas

------------------------------------------------------------
itl Global Services - Webbased Services
Web: http://www.itl-gs.com

------------------------------------------------------------



Mon, 29 Nov 2004 22:22:37 GMT  
 Clear method and collection
Hi Andreas ,

But It doesn't work in my case because I use a "custom" key (for example :
"120T15B" like a serial number)
 for my collection .

So do you have an another idea to do the job ?

Regards

Jean-Yves



Quote:
> Hi Jean-Yves

> In this case I always do it like this:

> Public Sub Clear()
>   For I = MyCollection.Count To 1 Step -1
>     MyCollection.Remove I
>   Next
> End Sub

> Regards
> Andreas

> ------------------------------------------------------------
> itl Global Services - Webbased Services
> Web: http://www.itl-gs.com

> ------------------------------------------------------------



Mon, 29 Nov 2004 22:30:23 GMT  
 Clear method and collection
Sorry Andreas ,

You are right it works .

Regards,

Jean-Yves



Quote:
> Hi Andreas ,

> But It doesn't work in my case because I use a "custom" key (for example :
> "120T15B" like a serial number)
>  for my collection .

> So do you have an another idea to do the job ?

> Regards

> Jean-Yves



> > Hi Jean-Yves

> > In this case I always do it like this:

> > Public Sub Clear()
> >   For I = MyCollection.Count To 1 Step -1
> >     MyCollection.Remove I
> >   Next
> > End Sub

> > Regards
> > Andreas

> > ------------------------------------------------------------
> > itl Global Services - Webbased Services
> > Web: http://www.itl-gs.com

> > ------------------------------------------------------------



Tue, 30 Nov 2004 19:23:20 GMT  
 Clear method and collection
Hi Jean-Yves

I tried out the following and it works fine.
For the Remove Function of the Collection you can use the "custom key" you
defined OR the unique index in the collection:

Private Sub Command1_Click()
Dim mCol As Collection

  Set mCol = New Collection
  For I = 1 To 10
    mCol.Add Command1, "120T" & I & "B"
  Next
  'mCol.Count is 10
  For I = mCol.Count To 1 Step -1
    mCol.Remove I
  Next
  'mCol.Count is Zero

End Sub

If it dosen't works, do you have a code example for me?
Regards
Andreas

------------------------------------------------------------
itl Global Services - Webbased Services
Web: http://www.itl-gs.com

------------------------------------------------------------



Tue, 30 Nov 2004 19:34:26 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. How can i clear the MSHFLEXGRID without CLEAR - Como limpar a GRID sem usar CLEAR

2. Clearing DAO error collection

3. Overriding Clear() for a Collection Class

4. Clearing a collection

5. Clearing the Command Objects Parameter Collection for re-use

6. Clearing the Command Objects Parameter Collection for re-use

7. Bookmark collection with DataGrid control not cleared

8. Clear collection of all members?

9. Faster method to clear large table?

10. Object.Undo method not clearing the Dirty property

11. easiest DAO database clearing method in VB6?

12. UpdateRecord method clears data bound controls - Why?

 

 
Powered by phpBB® Forum Software