Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Use Objptr function to quickly locate an object in a Collection

Total Hit ( 3118)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


One of the simplest and most effective uses of the ObjPtr function is to provide a key for quickly locating an object in a Collection. Let's suppose you have a collection of objects that don't have a property that can be used as a key to retrieve them in a collection. You can work around this by using the value returned by the ObjPtr function as the key in the collection:

Click here to copy the following block
Dim col As New Collection
Dim obj As CPerson

' create a new CPerson object and add it to the collection
Set obj = New CPerson
obj.Name = "John Smith"
col.Add obj, CStr(ObjPtr(obj)) 'the key must be a string

Because any object has a distinct ObjPtr value, and this value is guaranteed immutable, it is very easily to quickly retrieve it in the collection:

Click here to copy the following block
' remove the object from the collection
col.Remove CStr(ObjPtr(obj))

The same trick can be applied to any type of objects, including VB forms and controls, and external objects.


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.