Home All Groups Group Topic Archive Search About
Author
25 Mar 2009 7:45 PM
greg
Hello,
I am looking for the best way to create an ordered list.
However as I read in each piece of data, I would like to slide it into an
ordered list.  By my own logic/rules.

Is the simplest way to do this is to use an array and a temporary array?
looping and copying the data into the second array.  untill you get to the
new data to add.  then loop the rest of the original array?

or is there internal vb functions that can help out?

thanks

Author
25 Mar 2009 8:13 PM
Ralph
"greg" <iu***@ghfhg.com> wrote in message
news:O4i%23FJYrJHA.1304@TK2MSFTNGP05.phx.gbl...
> Hello,
> I am looking for the best way to create an ordered list.
> However as I read in each piece of data, I would like to slide it into an
> ordered list.  By my own logic/rules.
>
> Is the simplest way to do this is to use an array and a temporary array?
> looping and copying the data into the second array.  untill you get to the
> new data to add.  then loop the rest of the original array?
>
> or is there internal vb functions that can help out?
>

lol

Define "simplest" and "own logic/rules". (or for that matter "sorta".)

If just alphabetic, etc. you could create a hidden list box, fill it, then
sort it....
Simple but hacky? (is that a word?).

If the "rules" are complex, and known before collected, then create an
object (class) to hold the rules and a store, perhaps a link-list, thus
stuffing the data as it receives it. Maybe a binary tree?

If the data is in multiple pieces with one piece the key, then you might
want to create a "hash" with the key with an index/pointer to where the rest
is stored. (ie, sort the "keys"), etc.

In other words a couple of zillion ways to go about it. All simple, or not,
depending.

So give some more info; How many of these things? How long you going to
store them? What the rules? Items between 0-9, 10-19, ..? Items belonging to
several color groups? Or just stuff bigger or smaller than other stuff? What
are you doing now?

And someone will be along with some good and likely more appropriate advice.

-ralph
Are all your drivers up to date? click for free checkup

Author
25 Mar 2009 8:25 PM
Jim Mack
greg wrote:
> Hello,
> I am looking for the best way to create an ordered list.
> However as I read in each piece of data, I would like to slide it
> into an ordered list.  By my own logic/rules.
>
> Is the simplest way to do this is to use an array and a temporary
> array? looping and copying the data into the second array.  untill
> you get to the new data to add.  then loop the rest of the original
> array?

For a few items, that wouldn't be so bad.

But you're much better off in general with a linked list -- doubly
linked if you have to traverse it in both directions.

You can build a linked list with a parallel index array, or you can
incorporate the links and the data into a UDT or a class. A class is
more flexible, but a simple index will be fastest. Except for fairly
large data sets, the actual speed won't matter much.

Also, take a look at the Dictionary object, which may already do what
you need.

--
   Jim Mack
   Twisted tees at http://www.cafepress.com/2050inc
   "We sew confusion"
Author
25 Mar 2009 8:45 PM
Schmidt
"greg" <iu***@ghfhg.com> schrieb im Newsbeitrag
news:O4i%23FJYrJHA.1304@TK2MSFTNGP05.phx.gbl...

> I am looking for the best way to create an ordered list.
> However as I read in each piece of data, I would like
> to slide it into an ordered list.  By my own logic/rules.

If you have no problems with adding a library (introducing
a dependency to your project), then you can make use
of a nice "universal" container-object, which covers a
lot of the usual usecases in this regard.

This object is called cCollection and it comes within
my free toolset:
www.datenhaus.de/Downloads/dhRichClient3.zip
www.datenhaus.de/Downloads/dhRichClient3-Demo.zip

With that Object you can simply add the SortKey + Value-
pairs as they come in (e.g. from a parser).

Dim C as cCollection
    Set C = New cCollection
    'in your parsing-loop (repeatedly)
      'split your pair into a Value and a Key beforehand
      C.Add Value, Key
    'parsing-loop ends

Then in your App you can use this Container and
enumerate the added values either by AddOrder
(unsorted):
For i = 0 to C.Count - 1
    debug.print C.KeyByIndex(i), C.ItemByIndex(i)
Next i


Or in SortedKey-Order from the same Content with:
For i = 0 to C.SortkeysCount-1 'ascending
    debug.print C.KeyBySortkeyIndex(i), C.ItemBySortKeyIndex(i)
Next i
or descending:
For i =  C.SortkeysCount-1 To 0 Step -1
    debug.print C.KeyBySortkeyIndex(i), C.ItemBySortKeyIndex(i)
Next i

The Values can be Variants (holding Arrays or Objects if you want)
and the Keys can either be Strings, but also Longs, Currencies or
Doubles/Dates, which then will speedup the sorting (and also the
Adding) because the Binary-Search-Algo can then make direct
use of these "non-string"-DataTypes - and things should work
even faster this way (though mixed SortKeys - e.g. String-Keys,
mixed with Long-Keys are not allowed inside a single cCollection-
Container).

The cCollection is by default (after instantiation) compatible to
the VB-Collection - so, to enable the enhanced stuff (as e.g.
NonUnique-Keys - or NonString-Keys), you will have to
switch the .CompatibleToVBCollection - Property to False.

Olaf

Bookmark and Share