Collections and Classes
Results 1 to 4 of 4

Thread: Collections and Classes
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Feb 2014
    Location
    Spain
    Posts
    38
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Collections and Classes

    Hi,

    Can anyone help me with this?

    I have a class, lets say with Name, Address and Salary properties. And a Collection (Employees) with all the classes.

    Is there a way to search for the maxvalue of the Salary, from all the classes in the collection?

    Thanks!

  2. #2
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,830
    Post Thanks / Like
    Mentioned
    35 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Collections and Classes

    Try something like this...

        Dim Employees       As New Collection
        Dim cEmp            As clsEmp
        Dim sEmployee       As String
        Dim MaxSalary       As Double
        
        'Your code to store class objects in your collection
        
        MaxSalary = 0
        For Each cEmp In Employees
            If cEmp.Salary > MaxSalary Then
                MaxSalary = cEmp.Salary
                sEmployee = cEmp.Name
            End If
        Next cEmp
        
        MsgBox "Employee:  " & sEmployee & "; Salary:  " & MaxSalary
        


    Hope this helps!

  3. #3
    New Member
    Join Date
    Feb 2014
    Location
    Spain
    Posts
    38
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Collections and Classes

    Thanks, this works fine!

  4. #4
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,830
    Post Thanks / Like
    Mentioned
    35 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Collections and Classes

    You're very welcome!

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •