3
votes

I'm making a report that will display a list of costumers and some numeric values. I use a formula in order to sort my group, wich is the following :

if {Db.SortOrder} = 0 then
    {Db.CostumerName}
else
     ToText({Db.Value},'00000000',0,'') 

In this way i can group by costumer name or value, the problem is that i need to use a different sorting order for them, ascending order when i group by CostumerName and descending when i group by Value. How can i achieve that ? I've tried the "Sort group by formula" using crAscendingOrder,crDescendingOrder but it said i needed tu use a costant and not a variable (in my case i used db.SortOrder)

2

2 Answers

10
votes

My approach:

First, create a parameter field ({?Sorted Field}) to choose the sorted field: String; static list that includes 'Customer' and 'Value'; default value is 'Customer'

Next, create a custom function that will convert a string into its ASCII representation, allowing the order to be changed:

// ASCII()
Function (Stringvar characters, Optional Numbervar direction:=crAscendingOrder)

Local numbervar i;
Local stringvar c;

For i:= 1 To Len(characters) Do (
    If direction=crAscendingOrder Then
        c:=c + ToText( Ascw(Mid(characters,i,1)), "#")
    Else
        c:=c + ToText( 256- Ascw(Mid(characters,i,1)), "#")
);

c;

Next, create a formula field that will be used for sorting:

// {@Sorted Field}
Select {?Sorted Field}
Case "Customer": {Db.Customer}
Case "Value": ASCII(ToText({Db.Value},'00000000',0,''), crDescendingOrder)
Default: {Db.Customer}

Finally, reference this field in the record-sort expert:

enter image description here

0
votes

in my case i only needed to choose the field to sort by. i created the parameter field called SortField as static text and created the three friendly values i wanted to show, then created the formula that referenced it. i have crystal 2011 so my formula looks like this:

// {@Sorted Field}
Select {?SortField}
Case "BIN":{V_ITEM_MASTER.BIN}
Case "ORDER REF":{V_ITEM_MASTER.HEAT}
Case "PART":{V_ITEM_MASTER.PART}
Default: {V_ITEM_MASTER.BIN}