[Resolved] Sort items in an array-VBForums
Results 1 to 10 of 10

Thread: [Resolved] Sort items in an array

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2014
    Posts
    5

    Resolved [Resolved] Sort items in an array

    Hi

    I have an array (which comes from a search result) with words and numbers.
    How do I sort it 0-9+A-Z and Z-A+9-0?

    Thanks!
    Last edited by thedossetup; May 4th, 2014 at 06:59 PM.

  2. #2
    Addicted Member
    Join Date
    Jul 2011
    Location
    Mumbai
    Posts
    206

    Re: Sort items in an array

    other character i.e + & - are alternating in ur sequence
    Is tat sequence should be followed same or it not compulsion
    NAMO NANASHA

  3. #3
    PowerPoster
    Join Date
    Oct 2013
    Posts
    2,846

    Re: Sort items in an array

    What is your actual question?
    Do you need a sorting routine or do you have a sort routine but you need a different order?

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,268

    Re: Sort items in an array

    Can you post your professor's actual assignment? We might better understand your issue.

    What I THINK you want is that you ahve something like this:
    Code:
    4
    3
    5
    a
    D
    3
    t
    4
    9
    V
    and you might want it sorted, first, like this:
    Code:
    3
    3
    4
    4
    5
    9
    a
    t
    D
    V
    and then like this:
    Code:
    V
    D
    t
    a
    9
    5
    4
    4
    3
    3
    (Or, you might also not care if the letters are caps or not, in which case the first of the two sorts I would expect would look like this:

    Code:
    3
    3
    4
    4
    5
    9
    a
    D
    t
    V
    good guess?
    Last edited by SamOscarBrown; Apr 29th, 2014 at 11:51 AM.

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2014
    Posts
    5

    Re: Sort items in an array

    Quote Originally Posted by bhavik View Post
    other character i.e + & - are alternating in ur sequence
    Is tat sequence should be followed same or it not compulsion
    Only letters and numbers. Thanks.

    Quote Originally Posted by Arnoutdv View Post
    What is your actual question?
    Do you need a sorting routine or do you have a sort routine but you need a different order?
    I need a sorting routine. Sorry for bad english... Thanks.

    Quote Originally Posted by SamOscarBrown View Post
    Can you post your professor's actual assignment? We might better understand your issue.

    What I THINK you want is that you ahve something like this:
    Code:
    4
    3
    5
    a
    D
    3
    t
    4
    9
    V
    and you might want it sorted, first, like this:
    Code:
    3
    3
    4
    4
    5
    9
    a
    t
    D
    V
    and then like this:
    Code:
    V
    D
    t
    a
    9
    5
    4
    4
    3
    3
    (Or, you might also not care if the letters are caps or not, in which case the first of the two sorts I would expect would look like this:

    Code:
    3
    3
    4
    4
    5
    9
    a
    D
    t
    V
    good guess?
    Your 100% right. How do I do? Thanks.

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,268

    Re: Sort items in an array

    Well, the SIMPLE way to do 1/2 of it, is to put the values in a listbox (with the property sorted set to true). BUT, I know you are looking for a sorting algorithm so you can reverse the process as well. If you google sorting arrays, you will find a lot of hints. I am sure someone will gin up something for you as well...I will if I have time....busy right now.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,515

    Re: Sort items in an array

    While you could go shopping in the CodeBank here for a thread covering many common sorting algorithms, it sounds like all you need is simple sorting of String arrays.

    One algorithm that is fast and doesn't have the risk of nasty worst-case performance and possible self-destruction (I'm looking at you, Quick Sort) is the Heap Sort. I have one with both ascending and descending sorts and several compare options: Binary, Text, and "Insensitive."

    The risk with a Text comparison is that some differing characters compare lexically as equal even though they are different, and characters such as hyphens and apostrophes can be ignored as insignificant. However "Insensitive" compares is the slowest of the three options.


    Most of the size of the attachment is due to included sample data.
    Attached Files Attached Files
    Last edited by dilettante; May 1st, 2014 at 11:37 AM.

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2014
    Posts
    5

    Re: Sort items in an array

    Thanks both of you

  9. #9
    Hyperactive Member Daniel Duta's Avatar
    Join Date
    Feb 2011
    Location
    Bucharest, Romania
    Posts
    263

    Re: Sort items in an array

    When I tried to test the sample above each time a run-time error appears. The app requires a reference to "Edanmo's OLE interfaces & functions v1.81" ... It seems this reference is not related to the sort function in any way as long as once it is eliminated everything works properly.
    Last edited by Daniel Duta; May 1st, 2014 at 05:26 AM.

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,515

    Re: Sort items in an array

    Ahh, good point. Thank you for bringing it up.

    It was left in there when this was created from a much larger, older Project. I will repost the archive to spare future viewers that problem.

    This is a very commonly used TLB so a lot of people will never have bumped into it. Sorry.

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.