I am trying to have 2 columns and trying to sort the first column in ascending order and secondary sort should be the 2nd column in ascending order.
Please suggest or provide any logic for the same.
Thanks
I am trying to have 2 columns and trying to sort the first column in ascending order and secondary sort should be the 2nd column in ascending order.
Please suggest or provide any logic for the same.
Thanks
Subject: RE: Sorting
Before, you asked about sorting arrays. I assume this is the same question. In general, I think you’ll find that if you give the big picture, you’ll get better answers than if you just ask about a little detail of the implementation; if you’re going about the whole thing wrong, how can we tell?
Your question is a little vague, since by “columns” I don’t know for sure whether you mean view columns or columns in a table on a form. And if a table on a form, I’m not sure whether you mean that you have a separate field for each row and column, or a multi-valued field for each column, or what. I think this blog entry might answer your question: Generalized table sorting class.
It doesn’t handle the case of sorting one column ascending and the other descending, but you could customize the compare method to do that, very easily.
If the above does not solve your problem, we need more information about what you’re doing. If you’re not sure what information to supply, the C R I S P Y document might help you.
Useful blog: Best Practice Makes Perfect
Subject: RE: Sorting
I have called this agent thru WebQUeryOpen event wherein when page open it runs and place all the data in richtext.
This agent is creating a HTML table by populating and
tags in richtext. I am creating 3 colums using table tag. And every columns values are populating using arrays i.e. 3 arrays for 3 columns. Now I have to first sort 2nd column(2nd array) in ascending order and then based on this I have to sort 1st column(1st array) again in ascending order.Example:
This sorting should be same like as we are having the feature in MS excel wherein we define 2 conditions for sorting. Ex. Sort by column A and then by column B.
Hope I have now explained it well.
Thanks
Subject: RE: Sorting
You have a choice to make. You can either do it in a way that doesn’t require you to learn anything new, but is dumb and labor-intensive, or you can broaden your horizons by learning how to define your own class to contain one row of data, and sort those row objects. That’s actually less work, because you don’t have to understand and customize the sorting algorithm – you can just use an existing sorting class and add the information that’s specific to your data in a well-defined way.
To do it without having to learn anything new:
Take any array sorting algorithm you find anywhere on the internet – I’m sure you can even find approximately 1700 that are already written in LotusScript. At some point the algorithm will test two elements A(i) and A(j) against each other to see which comes first. Change that test: check A(i) against A(j) and if they’re equal, test B(i) against B(j).
Dim bGreater As Boolean
If A(i) > A(j) Then
bGreater = True
Else If A(i) < A(j) Then
bGreater = False
Else
bGreater = B(i) < B(j)
End If
If bGreater Then …
At some other point in the code, the algorithm will exchange elements in the array, probably something like:
tmp = A(i)
A(i) = A(j)
A(j) = tmp
you just need to repeat this for each array.
If you’re willing to learn something:
Download the Domino Design Library Examples and read about the ObjectSortedCollection class. Look at the example in there. Defining your own class to contain ONE ROW of your data and coding a method to say which of two rows comes first, is simple. Then you can easily handle one row as a unit. You don’t have to go delving in the sorting code and trying to change things around.