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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting values in an array

Status
Not open for further replies.

CBMC

Programmer
Nov 22, 2001
13
CA
I am having difficulty finding a way to store values in an array in sorted order in CR 8.

The elements I want to store are numbers and even if I try to set the record sort order, they keep being stored in my array in the original order.

I am a newbie at this, so any help would be appreciated.
Thanks.
 
Can you explain why you are trying to sort array values as there may be an alternative method of achieving your aim. Steve Phillips, Crystal Consultant
 
If you do need to sort arrays though, how about using the following bubblesort method:
Code:
rem // This formula sorts the elements in Array A using a standard bubble sort
rem // NOTE: This uses Basic Syntax not Crystal Syntax!

dim A
A = Array (10,9,8,7,6,5,4,3,2,1)

dim x, y, temp

for x = 1 to Ubound(A)
   for y = 1 to Ubound(A)-1
       if A(y) > A(y+1) then 
          temp=A(y)
          A(y)=A(y+1)
          A(y+1)=temp
       end if
   next y
next x

formula = A(10)

Hope that helps. Steve Phillips, Crystal Consultant
 
Hi SMPhillips - thanks for the response.

Basically, the values I am storing are times and each time has an associated count number.

I want to find a 60 minute interval in which the sum of the counts are a maximum. I was hoping to use the array to do the calculations.

I will try your bubblesort algorithm to see if that helps. Also, would you know if it is better to use Basic syntax over Crystal syntax when dealing with arrays?

Thanks
 
I would not say one is better than the other, whatever gets the job done is most important. I tried using Crystal syntax at first but found basic syntax easiest for this particular problem.

Hope it solves your problem. Steve Phillips, Crystal Consultant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top