DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2006
    Posts
    1

    Angry Accessing the properties of an object in a collection - VB.net

    Hello. I've got a number of objects in a collection, and I'd like to access their properties. However, I can't access their properties unless I loop through the collection in the following way:

    for each inst as obj in collection
    inst.property = 5
    next

    I'd like to be able to access objects based on their index number, such as in the following:

    for each inst as obj in collection
    if inst.property = 5 then
    inst(12).property = "success"
    end if
    next

    Is this possible?

    If it helps, the collection was defined as type Microsoft.VisualBasic.Collection()

    Thank you!

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    The variable 'inst' is not a collection, it's a single object, so you cannot access inst(12). If your collection is named 'collection', as your code suggests, then you should be able to do this:
    Code:
    For Each inst As YourClass In collection
        If inst.Property = 5 Then
            collection(12).Property = "success"
        End If
    Next
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Similar Threads

  1. Replies: 1
    Last Post: 11-28-2005, 04:15 PM
  2. VB.NET Grid properties?
    By THIEFs in forum .NET
    Replies: 0
    Last Post: 07-25-2003, 06:33 AM
  3. Converting VB.Net code to C#
    By Greg Rothlander in forum .NET
    Replies: 0
    Last Post: 07-24-2003, 04:35 PM
  4. Validating XML
    By Jaco de Villiers in forum XML
    Replies: 1
    Last Post: 06-01-2001, 05:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links