LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Implementing Binary Comparisions for a class objects

Thank-you David, that's a good solution.

Just for the record:

- an array would be a easier solution but my Table class does more then just
store data. Some of the table fields are calculated when required using the
get and let functions. As thie information can be calculated, and may not be
required, I don't store it and only calculate it when required.

- A simple excel SORT is impossible in this situation. I have several
tables which consists of a title row, followed by an undetermined number of
invoices, and finally a closing balance "total" line. Excel's sort function
isn't set-up to maintain groups of related lines together.

- What I'm doing isn't as complicated as you all seem to think. I guess you
could say I've recreated a relational system, I prefer to think of it as
efficient memory management. The original data source is in a remote
location, although it would be possible to re-query the database and return
the information in the required order, it is more efficient to maintain the
data in a proper structure on the client side. Otherwise I'll have all the
data processing happening on my server and a nice fast client desktop sitting
there doing nothing.

finally, many thanks to you all for your help it is very much appreciated.


- Rm





"David Welch" wrote:

Robert Mulroney wrote:
I have implemented a class in VBA and I'm storing multiple instances of the
class in a collection. I would now like to sort the objects in the collection
based on one of the class properties. Which property we sort by will be
determined at run-time.

I've written a procedure that can sort items in a collection but it relies
on using binary operators (, <, =, ect) to rate one collection item against
the next. That's all fine if you're only storing primitive types in the
collection, I have a homogeneous collection of objects how can I compare one
to the next?

I have seen people implement an "=" method for a class in C#.net (no I can't
remember how they did it), but can you do anything like that in VBA.

- Rm

Unfortunatly you can't implement operators (eg +,-,<,) in VB. But you
could write an accessor class which would return a value from an object,
and then sort by that value. eg

AccessorValue.cls
-----------------

function Value(byval obj as object) as variant
Value = obj.Value
end function

then pass the class to your sort routine.

set SortedCollection = SortCollection(Collection, new AccessorValue)

where your SortCollection routine uses the Value returned by the
accessor object to do the comparision, eg:

rather than
If Obj1.Value < Obj2.Value Then

you do:
If Accessor(Obj1.Value) < Accessor(Obj2.Value) Then

And so on.

---
Dave

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
implementing help for UDF [email protected] Excel Discussion (Misc queries) 3 May 10th 07 12:05 PM
Solver returns non binary answer in binary constrained cells Navy Student Excel Worksheet Functions 6 September 1st 05 03:11 PM
Binary operations (left/right shift, binary and/or, etc.) Mike Hodgson Excel Programming 4 June 17th 05 09:27 AM
VBA & XL2K: Working with objects/class modules Mike Mertes Excel Programming 0 November 1st 04 02:55 PM
new class w/ graphic objects Tony Rizzo Excel Programming 1 June 7th 04 02:18 PM


All times are GMT +1. The time now is 05:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"