Quick Search for:  in language:    
VBSEE,NEW,replacement,existing,Collection,VER
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Visual Basic Stats

 Code: 3,290,928. lines
 Jobs: 179. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login





Latest Code Ticker for Visual Basic.
Check Placement of Form on Screen
By CubeSolver on 11/20


RT Full Duplex
By Brian Black on 11/20


C++ Template Hack
By OpcodeVoid on 11/20


Click here to see a screenshot of this code!DeskTop Generator
By Ziad Said on 11/20

(Screen Shot)

SQLMan
By Darwin H. de Leon on 11/20


Klik! CompareLib...Co mpare and synchronize schema differences in your Access databases...
By Özden Irmak on 11/20


listview000sher if
By Sherif Omran on 11/20


Using ComboBox instead of TextBox
By SMA Soft on 11/20


Click here to see a screenshot of this code!ColorFade
By SMA Soft on 11/19

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

CollectionPlus ! (See VERSION 2)

Print
Email
 

Submitted on: 5/27/1999
By: Rick 
Level: Not Given
User Rating: By 101 Users
Compatibility:VB 5.0, VB 6.0

Users have accessed this code 8601 times.
 
 
     'In replacement of existing Collection in VB 'SEE MY NEW VERSION !
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

'**************************************
' Name: CollectionPlus ! (See VERSION 2)
'     
' Description:'In replacement of existin
'     g Collection in VB
'SEE MY NEW VERSION !
' By: Rick
'
' Inputs:'Same as Collection
'
' Returns:'Same as Collection with mores

'     Subs and Property

' ' Assumes:'CollectionPlus his based on e ' xisting Collection, but you can ask ques ' tion like 'ifKeyIsThere ou ifItemIsThere , returns ' True or False. 'A Public Event Error is available. 'It's a very simple code but useful ! 'In my next version i'm gonna handle Ite ' m,Key and Group 'so after you can mix that CollectionPlu ' sB with ListBox or other Control. ' ' Side Effects:'None ' 'This code is copyrighted and has' limited warranties.Please see http://w ' ww.Planet-Source-Code.com/vb/scripts/Sho ' wCode.asp?txtCodeId=1899&lngWId;=1'for details.'************************************** '*************************************** ' ************************ ' CLASS '*************************************** ' ************************ 'SEE MY NEW VERSION 'Create a New Class and name it Collecti ' onPlus (optional) 'Copy/Paste the following Code 'Creer une nouvelle Class et nommez-la C ' ollectionPlus 'Copier/Coller toutes les prochaines lig ' nes Option Explicit Dim theCollection As New Collection Private m_Delim As String Const DefaultDelim As String = "," Public Event Erreur(ByVal FunctionName As String, ByVal Number As Long, ByVal Description As String, ByVal DataError As String) Private Sub Class_Initialize()
m_Delim = DefaultDelim End Sub
Private Sub Class_Terminate()
Set theCollection = Nothing End Sub
Public Sub Add(Item As Variant, Optional ByVal Key As Variant, Optional ByVal Before As Variant, Optional ByVal After As Variant)
On Error Goto err_Occur theCollection.Add Item, Key, Before, After On Error Goto 0 err_Continu: Exit Sub err_Occur: RaiseEvent Erreur("Add", Err.Number, Err.Description, "") Resume err_Continu End Sub
Public Sub RemoveKey(ByVal Key As String)
On Error Goto err_Occur theCollection.Remove Key On Error Goto 0 err_Continu: Exit Sub err_Occur: RaiseEvent Erreur("RemoveKey", Err.Number, Err.Description, Key) Resume err_Continu End Sub
Public Sub Remove(ByVal IndexOrKey As Variant)
On Error Goto err_Occur theCollection.Remove IndexOrKey On Error Goto 0 err_Continu: Exit Sub err_Occur: RaiseEvent Erreur("Remove", Err.Number, Err.Description, IndexOrKey) Resume err_Continu End Sub
Public Sub RemoveIndex(ByVal Index As Long)
On Error Goto err_Occur If Index <= theCollection.Count Then theCollection.Remove Index Else RaiseEvent Erreur("RemoveIndex", 9, "Subscript out of range, Max=" + CStr(theCollection.Count), Index) End If
On Error Goto 0 err_Continu: Exit Sub err_Occur: MsgBox Err.Number RaiseEvent Erreur("RemoveIndex", Err.Number, Err.Description, Index) Resume err_Continu End Sub
Public Sub RemoveAll()
If theCollection.Count = 0 Then Exit Sub Dim element As Variant For Each element In theCollection theCollection.Remove 1 Next element
End Sub
Public Property Get Count() As Long
On Error Goto err_Occur Count = theCollection.Count On Error Goto 0 err_Continu: Exit Function err_Occur: RaiseEvent Erreur("Count", Err.Number, Err.Description, "") Resume err_Continu End Property
Public Function Item(ByVal IndexOrKey As Variant) As Variant
On Error Goto err_Occur Item = theCollection.Item(IndexOrKey) On Error Goto 0 err_Continu: Exit Function err_Occur: RaiseEvent Erreur("Item", Err.Number, Err.Description, IndexOrKey) Resume err_Continu End Function
Public Function IfItemIsThere(ByVal Index As Long) As Boolean
Dim temp As Variant On Error Goto err_Occur temp = theCollection.Item(Index) On Error Goto 0 IfItemIsThere = True err_Continu: Exit Function err_Occur: IfItemIsThere = False Resume err_Continu End Function
Public Function IfKeyIsThere(ByVal Key As String) As Boolean
Dim temp As Variant On Error Goto err_Occur temp = theCollection.Item(Key) On Error Goto 0 IfKeyIsThere = True err_Continu: Exit Function err_Occur: IfKeyIsThere = False Resume err_Continu End Function
Public Property Get DelimStringDataError() As String
DelimStringDataError = m_Delim End Property
Public Property Let DelimStringDataError(ByVal NewDelim As String)
m_Delim = NewDelim End Property
'*************************************** ' ************************ ' FORM '*************************************** ' ************************ 'Copy/Paste this lines in a Form called ' frmMain 'Copier/Coller ces lignes dans une Form ' nommer frmMain Option Explicit 'The Declaration for Handle the Error Ev ' ent of Collection Plus Dim WithEvents myCol As CollectionPlus Private Sub Form_Load()
'Initialize Collection Set myCol = New CollectionPlus End Sub
Private Sub Form_Unload(Cancel As Integer)
Set myCol = Nothing Set frmMain = Nothing End End Sub
Private Sub cmdTestCol_Click()
'The Add,Item,Remove and Count are same ' as Collection myCol.Add "My Item", "My Key" ' ,"Before Key","After Key" [Optional] myCol.Add "Second" 'Verify my Items MsgBox "Have Item 1 : " + CStr(myCol.IfItemIsThere(1)) + vbCrLf + vbCrLf + _ "Have Key 'My Key' : " + CStr(myCol.IfKeyIsThere("My Key")) + vbCrLf + vbCrLf + _ "Have Item 3 : " + CStr(myCol.IfItemIsThere(3)), _ vbInformation + vbSystemModal, "CollectionPlus" 'An Error Event Occur (without Crash !) myCol.Remove 5 'This gonna Delete "Second" (Like Collec ' tion) myCol.RemoveKey "" 'Get Count MsgBox "Collection Count: " + CStr(myCol.Count), vbInformation + vbSystemModal, "CollectionPlus" 'Now Remove All Items myCol.RemoveAll End Sub
'Error Event of CollectionPlus Private Sub myCol_Erreur(ByVal FunctionName As String, ByVal Number As Long, ByVal Description As String, ByVal DataError As String)
MsgBox "FunctionName: " + FunctionName + vbCrLf + "Number: " + CStr(Number) + vbCrLf + _ "Description: " + Description + vbCrLf + "DataError: " + DataError, _ vbInformation + vbSystemModal, "Error Event CollectionPlus !" End Sub


Other 1 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
6/30/1999 9:17:00 AM:JR
This code works fine, but there are a 
couple of implementation issues to 
keep 
in mind.  
First, if you want 
CollectionPlus to 
behave like 
Collection, you need to
set Item as 
the default method.
Second, if you 
want FOR EACH to work
on 
CollectionPlus, you need to
implement 
delegation of the enumerator
via a 
hidden NewEnum function.
Both these 
issues are covered well in
the 
"Creating Your Own Collection
Class" 
topic of the VB6 documentation,
so 
look there for details.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/5/1999 11:14:00 AM:Rick
Thanks for comment JR,
now see my 
Second version !
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Visual Basic Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.