+ Reply to Thread
Results 1 to 7 of 7

quick sort code

  1. #1
    Registered User
    Join Date
    08-28-2008
    Location
    world
    Posts
    5

    quick sort code

    Hi, This may not be the best place for this but let's try anyway.

    I'd like to write some code to sort values manually. This will not end up being
    an Excel or VB project. It's a general routine that I want to bring over to
    UBasic which doesn't have a sort command as far as I know.

    I have 36 array variables of which the first 8 are chosen by nested For-Next
    loops. The remaining values are derived from these 8.

    To be usable for testing none of these 36 can be equal to each other. The
    simplest way I can think of to test for this is to sort ascending then compare
    one to the next. That way I only have 35 comparisons to make vs >600 otherwise.

    As I have 8 nested for-next loops that each go from 1 to 36 I need a good
    fast sort code that handles any equal values without going into an endless
    loop or bombing out. Other messages here don't seem to cover this particular situation.

    Thanks for any help.

    bc

  2. #2
    Registered User
    Join Date
    08-28-2008
    Location
    world
    Posts
    5
    Oh, I should mention that I have programmed this already in Excel and it runs just great. The cells themselves do a lot of the work so that the code is minimum.

    The only problem is that running it in Excel is about 200 times slower than UBasic. It would take months to run in Excel.

    bc

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello bceng,

    Having 8 levels of nesting is going to slow down even the fastest sort. The second problem is the examples. Examples given here will be for Excel and not UBasic. Unless you are comfortable with transitioning the code, the examples won't be of much use. You should probably evaluate your sort and search for a suitable sorting algorithm you can apply that doesn't require 8 levels of nesting.

    Sincerely,
    Leith Ross

  4. #4
    Registered User
    Join Date
    08-28-2008
    Location
    world
    Posts
    5
    The 8 levels of nesting isn't where the problem is. While time consuming it's still easy. And transitioning the code isn't too much of a problem as long as I can understand what the code is doing.

    The problem is that I don't know how to write a sort routine. While I probably could figure out a bubble code seems to me it will hang up if there are multiple equal values. And for quick sort I don't know how that's done.

    So I was just hoping someone here knew how it's all done without a pre-programmed command to do it for them. TIA.

    bc

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Here's QuickSort:
    Please Login or Register  to view this content.
    Last edited by shg; 08-29-2008 at 01:47 PM.

  6. #6
    Registered User
    Join Date
    08-28-2008
    Location
    world
    Posts
    5
    Thanks shg I'll try that.

  7. #7
    Registered User
    Join Date
    08-28-2008
    Location
    world
    Posts
    5

    sort routine works great

    Sorry it took so long to get back to you. You're code worked fine. I modified
    it a bit to do my specific task but it does just what I was looking for.

    Thanks.
    bc

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA code to renames Tabs dependent on Cell name
    By Zyphon in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-28-2008, 05:44 AM
  2. VBA Match or Find code
    By djvice in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-20-2008, 08:03 PM
  3. List all the combinations of a group of cells containing letters, but not numbers
    By tanaka1986 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 02-12-2008, 06:38 AM
  4. converting table to list
    By Malte in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 12-25-2007, 05:56 PM
  5. Problems understanding automated emailing code.
    By DDONNI in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-19-2007, 12:26 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1