Report View - Sorting Floats

Started by User_McUser, November 09, 2021, 12:11:23 PM

Previous topic - Next topic

User_McUser

I have a report view in a dynamic dialog with column sorting enabled. It works fine when sorting Integers or Strings but when I try to sort floating point numbers it seems to be using a character by character comparison.

For example, if I have three values - 1.05, 9.2, and 10.7 - the 10.7 will sort after the 1.05 but before the 9.2 where as I want them in actual numerical order.

Is there someway to change the sorting method used by the Report View or do I have to sort it "manually," either by calling ArraySort() or by writing my own sorting function?

How are values in an array stored anyways? Is this problem happening because the float is converted into a string when stored?

Thanks!

td

The ReportView control sorts using a code point sort method. The ArraySort function has other options including @STRINGSORT and @LOGICALSORT. Descriptions of all sort methods used by the ArraySort function can be found in the functions documentation.   You can presort an array using the ArraySort function. For example,

Code (winbatch) Select
aFloats = Arrayize('52.19,2.01,19.84,42.0',',')
ArraySort(aFloats,@ASCENDING | @LOGICALSORT )

RVFloatExFormat=`WWWDLGED,6.2`

RVFloatExCaption=`WIL Dialog 1`
RVFloatExX=730
RVFloatExY=216
RVFloatExWidth=518
RVFloatExHeight=324
RVFloatExNumControls=003
RVFloatExProcedure=`DEFAULT`
RVFloatExFont=`DEFAULT`
RVFloatExTextColor=`DEFAULT`
RVFloatExBackground=`DEFAULT,DEFAULT`
RVFloatExConfig=0
RVFloatExDPI=`192,10,20`

RVFloatEx001=`138,300,050,016,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,@csDefButton,DEFAULT,DEFAULT,DEFAULT`
RVFloatEx002=`329,300,049,016,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
RVFloatEx003=`079,041,355,235,REPORTVIEW,"ReportView_1",aFloats,DEFAULT,DEFAULT,30,@csNoHeader,DEFAULT,DEFAULT,DEFAULT`     
ButtonPushed=Dialog("RVFloatEx")


"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

User_McUser

Thanks! Though now I have a follow-up question:

My report view has multiple columns (5 in total) - how do I identify which specific column header was clicked when processing the @deRvhClick event in order to sort on the correct data?

td

Please read the following in the online documentation:

https://docs.winbatch.com/mergedProjects/WindowsInterfaceLanguage/html/ReportView_Control.htm

or in your copy of the Consolidate WIL help file at Consolidated WIL > Reference Guides > Windows Interface Language Reference > Things to Know > Dialogs > Dialog Control Types > ReportView Control.

Look for the @deRvhClick (22) entry in the table under the "Event Options" section of the controls documentation.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Should correct an inaccuracy I made in the second post in this topic thread. While it is true that the ReportView control sorts floating-point numbers via a word sort that is not true of integer values. The reason for the difference is something called representational error. Representational error is the result of the fact that floating numbers are stored in a binary format in computer memory. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade