Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting of Arrays - How is it done?

Status
Not open for further replies.

kaul125

Programmer
Jan 29, 2002
87
US
I'm selecting a record from a table and has multiple fields I need to address. I would like to put these values into an array and do processing on them. All the fields are integers. Once the values are in the array, I would like to sort the array. However, I have not found a PB fuction that sorts an array.

Is there a PB 6.5 sort function for array's? If so what is it call, because I don't see anything in PB Help. If there is no PB function are there any prewritten external funtions to do this? Or does anyone have an idea on how to sort arrays?

Thanks,

keith
 
How about building a datawindow over the table, using the dw in a (non-visual) datastore and modifying the sort order as required?
That way you could step through the datawindow rows in a loop much as you would use an array.
 
I believe you misunderstood my post.

For example, I have 5 columns returned in my query. Column 1 to 3 are of integer datatype and have the values of 21, 15, 60 respectively. I do not want to sort the by the columns. I want to sort the values in columns for each row.

In other words the result of the array for the first row would be:
array[1]=21
array[2]=15
array[3]=60

Then after sorting the array I would have:
array[2]=15
array[1]=21
array[3]=60

Keith
 
I think there's no function, you have to create one by yourself
 
Better solution is, insert values in datastore sort it and
use primary property.

your array [] = datastore.object.column.primary
 
Apart from above DS solution. you can actaully use ANY object with sort functionality in it.

Example of using listbox, add your value in it, then get them back to your array sequentially. The magic will be done by listbox object (as long as it sets sort flag on.)

Addison Lu
 
bubble sorts are good for arrays.

boolean lb_sorted

lb_sorted = false
do while not lb_sorted
for ll_row = 1 to x.RowCount() - 1
if x.value [ ll_row ] > x.value [ ll_row + 1 ] then
save row ll_row
copy row ll_row + 1 to ll_row
copy saved row to ll_row + 1
lb_sorted = false
end if
next
loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top