[Resolved] Sort items in an array-VBForums

# Thread: [Resolved] Sort items in an array

1. ## [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!

2. ## 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

3. ## 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. ## 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?

5. ## Re: Sort items in an array

Originally Posted by bhavik
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.

Originally Posted by Arnoutdv
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.

Originally Posted by SamOscarBrown
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. ## 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. ## 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.

8. ## Re: Sort items in an array

Thanks both of you

9. ## 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.

10. ## 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.

#### 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.