Re: Collection Structure

From: Dave (dave5397_at_btinternet.com)
Date: 04/27/04

  • Next message: alessandro sbenaglia: "Re: Collection Structure"
    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


  • Next message: alessandro sbenaglia: "Re: Collection Structure"

    Relevant Pages

    • sort 1-D array of doubles for Olaf Schmidt
      ... A few weeks Olaf Schmidt posted a VB6 routine to sort a 1-D array of strings very fast indeed. ... fastest way to change case of string. ... Dim i As Long, j As Long, Lo As Long, Hi As Long, StPtr As Long ...
      (microsoft.public.vb.general.discussion)
    • Re: About word frequency
      ... Use the split function to turn the string into an array. ... Sort the array. ... For each sLine in aList ...
      (microsoft.public.scripting.vbscript)
    • Re: Quick method to sort a list of strings?
      ... 'split string into an array around so each line is a seperate item ... the cell may represent the number of purchases by ... I do not have all the these comments stored in an array ... separate entities and sort them in alpha-numeric order? ...
      (microsoft.public.excel.programming)
    • RE: Quick method to sort a list of strings?
      ... 'split string into an array around so each line is a seperate item ... the cell may represent the number of purchases by ... I do not have all the these comments stored in an array ... separate entities and sort them in alpha-numeric order? ...
      (microsoft.public.excel.programming)
    • Help in French|Spanish|German translation.
      ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
      (microsoft.public.fox.helpwanted)

    Loading