Results 1 to 12 of 12

Thread: Sorting array by date

  1. #1

    Thread Starter
    Addicted Member sergeos's Avatar
    Join Date
    Apr 2009
    Location
    Belarus
    Posts
    167

    Sorting array by date

    Answer please, which sorting algorithms i can sorting this array:
    Field1; 2009-05-11
    Field2; 2009-10-20
    Field3; 2008-04-07

    so, result mst be like this:
    Field3; 2008-04-07
    Field1; 2009-05-11
    Field2; 2009-10-20

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Sorting array by date

    Is this data coming from a database? If so, recommend writing the query to return the fields already sorted -- easier to let the database do it for you.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Addicted Member sergeos's Avatar
    Join Date
    Apr 2009
    Location
    Belarus
    Posts
    167

    Re: Sorting array by date

    No, not from db.
    This array creating from data in random stream.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Sorting array by date

    Look at this thread by Ellis Dee, plenty of search algos to choose from.
    Tip: When sorting, ensure your array is of Date type variables or use CDate() in the sort function
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Addicted Member sergeos's Avatar
    Join Date
    Apr 2009
    Location
    Belarus
    Posts
    167

    Re: Sorting array by date

    Dear LaVolpe, i saw these examples of sorting, but i can't choose necessary for my challenge.

    And also, thanks for Tip!

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Sorting array by date

    Show us what your array looks like in code, how is it declared, how many dimensions.

    In that link, look at Ellis Dee's last post and maybe use the author's recommendation.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Addicted Member sergeos's Avatar
    Join Date
    Apr 2009
    Location
    Belarus
    Posts
    167

    Re: Sorting array by date

    originally, i am such a text file:

    Publisher:
    JSC Venturo
    IP Jorney
    DateOfPublish:
    2001-05-03
    2000-01-02
    Author:
    Smith
    John
    ...
    this i s little peace of example, the algrtmh of code is very difficult, the array have arr(x,6)
    i'm parse data to array:
    arr(0,0) = "JSC Venturo"
    arr(0,1) = "2001-05-03"
    arr(0,2) = "Smith"
    arr(1,0) = "IP Jorney"
    arr(1,1) ="2000-01-02"
    arr(1,2) ="John"

    the arr(x, 3 to 6) had other string data

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Sorting array by date

    See if Ellis Dee's 2D array sort is what you need?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    Addicted Member sergeos's Avatar
    Join Date
    Apr 2009
    Location
    Belarus
    Posts
    167

    Re: Sorting array by date

    Global thank you!
    Look likes good.
    Tommorow, (today morning) try to resolve my problem.

  10. #10

    Thread Starter
    Addicted Member sergeos's Avatar
    Join Date
    Apr 2009
    Location
    Belarus
    Posts
    167

    Re: Sorting array by date

    LaVolpe, ezright, the Ellis Dee's 2D array sort fine!
    Problem is resolve.

    P.S. but, maybe you know how possible sort other columns after first, such in SQL,
    for example, ORDER BY f(3), f(2), f(5)

  11. #11
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Sorting array by date

    All sorting algorithms can be described as being either stable or unstable.
    A stable sorting algorithm will maintain the relative order of equal keys whereas and unstable algorithm might not.

    Sorting by more than one column can be very simple with a stable algorithm. Simply sort the whole array by each of the columns you are interested in, starting with the column of least priority, finishing with the column of highest priority. Not exactly efficient, but simple.

    Alternatively a solution that works with both stable and unstable algorithms is to start by sorting the column of highest priority, if the sorted column contains any sections of duplicate keys then sort each (if any) of these sections by the next highest priority column. If the next column contains any duplicates then sort these by the column after that...

    If an unstable algorithm is used for the above and the final column contains duplicates then these sections might not maintain the original order. If stability is important then another column can be added to store the original order. This column can then be used for the final sort.

    It looks like you are using Quicksort which is an unstable algorithm.

    The sorting thread already linked to explains a lot more.

  12. #12

    Thread Starter
    Addicted Member sergeos's Avatar
    Join Date
    Apr 2009
    Location
    Belarus
    Posts
    167

    Re: Sorting array by date

    i resolve this problem by creating object adodb.recordset, fill rs with my array and apply .sort by 2 fields.

Posting Permissions

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



Click Here to Expand Forum to Full Width