Re: Collection Structure
From: Dave (dave5397_at_btinternet.com)
Date: 04/27/04
- Previous message: javi: "¿How Can i use Threads in VB6.0?"
- In reply to: Alessandro Sbenaglia: "Re: Collection Structure"
- Next in thread: alessandro sbenaglia: "Re: Collection Structure"
- Reply: alessandro sbenaglia: "Re: Collection Structure"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 27 Apr 2004 16:42:55 +0100
In VB:
Private Sub CreateIndexForCollection(inCollection as
Collection,outsIndex,outlIndex)
' inCollection is a collection of objects each of which has a string
property StringID you want
' to sort by (could be an Integer, Long or other property with
corresponding changes in the C++)
' outsIndex is the set of all StringID's in order
' outlIndex is a Long array of the index of the corresponding elements in
the collection
Dim psIndex() as String
Dim j as long
Redim pIndex(inCollection.Count-1)
For j=1 to inCollection.Count
pIndex(j-1)=inCollection(j).StringID 'or similar
Next j
' Pass this index to the C++ sorter
Call MySorter(pIndex,outIndex)
End Sub
In C++ depending on whether you use COM will determine headers etc, but the
method will be in a routine such as:
void DoTheSort(SAFEARRAY *inarr, SAFEARRAY *outarr);
where inarr is the String array and outarr is an array of longs containing
the Collection index corresponding to the (sorted) inarr. The routine
needs to sort the input array keeping track of the original position (I use
a structure called ELT defined as
struct ELT {
BSTR bstrval;
long idx;
};
to do this. You need to code a Compare routine comparing two ELT values to
insert into qsort. You then need to create the output VARIANT outIndex and
set the address of outarr into its parray element.
Hope this helps.
Dave
"Alessandro Sbenaglia" <anonymous@discussions.microsoft.com> wrote in
message news:3EC1E68F-FEC6-487C-B764-03F306F24643@microsoft.com...
> I don't understand...what sorts my collection? the array I create is by
copy I think. Please, show me a simple snippet
- Previous message: javi: "¿How Can i use Threads in VB6.0?"
- In reply to: Alessandro Sbenaglia: "Re: Collection Structure"
- Next in thread: alessandro sbenaglia: "Re: Collection Structure"
- Reply: alessandro sbenaglia: "Re: Collection Structure"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|