Listview sorting and index files

General development discussion.

Moderators: Susan Smith, admin, Gabriel

Post Reply
Susan Smith
Posts: 717
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Listview sorting and index files

Post by Susan Smith »

Hi all,

I read in the 4.20 release notes up on the wiki:
BR now supports aggregated sorting for LIST/GRIDs. This means when clicking on various column headings or programmatically sorting columns, fields of equal values retain their previous order within their new groupings.

I can't see how you do this programmatically. Does someone have a syntax diagram of how to presort a listview by several columns?

Secondly, if I have a listview that needs to be pre-sorted on 4 columns, which is the better choice (or does it make a difference, all other things being equal):
1. maintain an index for this purpose
2. presort by those 4 columns programmatically when the listview is built
Does it make any difference?

-- Susan
Gabriel
Posts: 412
Joined: Sun Aug 10, 2008 7:37 am
Location: Arlington, TX
Contact:

Post by Gabriel »

You just offer the sort command multiple times in a row on multiple columns.

What I do when I want special sorts is to add a hidden column that I sort based on, and I throw a chunk of data in there.

For example I sort my expenses by the uppercased first three characters of the expense description followed by the julian date. This makes it so that "Electric Bill January" comes right before "electricity bill february" on the list which is what I wanted - sinse the description field doesn't always contain valid data and it may be cased differently, this allows me to quickly make sure that a record is not missing.

The better way would have been to use an index but I wanted a quick and dirty solution that doesn't mess with the data file in my case.

Aggregate sorting is only supported in 4.2, right?
Susan Smith
Posts: 717
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Post by Susan Smith »

Yes, I believe that aggregate sorting was born in 4.2 - or so it seems to indicate in the release note document where I stumbled across it.

But I will probably use the hidden column to sort on then. That was always my backup plan, and it's easy to implement.

-- Susan
gtisdale
Posts: 218
Joined: Sun Jun 07, 2009 7:54 am
Location: Concord, Massachusetts
Contact:

Post by gtisdale »

Aggregatge sorting is a "cumulative" sort that treats each successive sort as if the previous sort was the native sequnce of data in the arrays. The actual native sequence, which can be reinstated byt adding a null record to the existing arrays, does not change.

The thing that is missing is a way to let the user/program know what fields were sorted on. Without this the user cannot sort the arrays into the sequence that is desirable and then print a report.

In terms of sequncing the arrays displayed I use FNSRTARY to sort the arrays before loading into the listbox. That way the "Native" sequnce is a sequnce that I can identify. (See FNSNAP.dll for FNSRTARY).

What is becoming more and more a standard of my lists and grids is a button to print the contents of the list. Having the contents in a "logical" order in the natural array sequnce facilitates this process. Also, printing the list to an RTF documnt in table/cell format allows the Wordprocessor that reads the document (Word of Open Office) to resort the document prior to printing.

FNGeorge
Susan Smith
Posts: 717
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Post by Susan Smith »

George wrote: What is becoming more and more a standard of my lists and grids is a button to print the contents of the list. Having the contents in a "logical" order in the natural array sequnce facilitates this process. Also, printing the list to an RTF documnt in table/cell format allows the Wordprocessor that reads the document (Word of Open Office) to resort the document prior to printing.

George, this is pretty interesting. I agree that the users often want to print the content of the listviews and grids and this is a valuable discussion to have for many of us. Do you "functionize" this process?

I like the idea of printing to an RTF file too - that's a valuable capability in the case that the user wants to manipulate the data first. I suppose you could also export that data into an Excel spreadsheet to accomplish similar things. Currently, I have BR reports that print to HTML and then automatically load Excel (via shell call) to load that data into spreadsheet format. In this case, it's because the accountants like to massage the data before they print the final financial statement. I'm assured that this is different than cooking the books! :lol:

But I'm confused about the print order. When you print the arrays in the grid, are they in the original order or the order that the user (or program) may have sorted them after the grid was displayed? When BR says (in the doc) that the arrays are not sorted if you sort them on the screen, is there no way to read that data back in order by the "altered" sort? I'm sure that I'm just missing something obvious here.

-- Susan
gordon
Posts: 358
Joined: Fri Apr 24, 2009 6:02 pm

Post by gordon »

I don't want to reveal too much right now but 4.3 screen IO will be adding as keywords- DISPLAYED_ORDER, RANGE and SORT_ORDER. These will be presented in detail at the conference.
gtisdale
Posts: 218
Joined: Sun Jun 07, 2009 7:54 am
Location: Concord, Massachusetts
Contact:

Post by gtisdale »

As of now (4.20E) there is no way for BR to know what order the user has sorted the data in the list arrays. The data read from the list arrays is in the same order that it was in when it was loaded into the list. Consequently, any report is in the original order regardless of the user's sort sequence. There is also no way for us to know what order the user sorted to by knowing the last column sorted on for example. If we did know this we could resort the arrays into that sequence prior to running the report.

It sounds like Gordon is going to give us the ability to get this information from the list with the 4.3 keywords to which he has referred.

As for printing to an RTF file, the following code creates an RTF file for one of my list/grid's

34500 IF FK=12 THEN
34510 LIBRARY ENV$("PD")&"vol002\RTFLIB.DLL": FNRTF,FNAMT$,FNTEXT$
34520 LIBRARY ENV$("PD")&"vol002\FNSNAP.DLL": FNMSEXE$,FNGETHANDLE
34530 DIM TYPES$(5)*2,STYLES$(5)*1000,MASK$*20,RTFFILE$*100,RTFOUT$*100
34540 LET MASK$="pic(-,---,--#.##)"
34550 OPEN #(RTFFILE:=FNGETHANDLE): "name="&ENV$("temp")&"\temp"&SESSION$&".txt,recl=2000,replace",DISPLAY,OUTPUT
34560 PRINT #RTFFILE: "H|[SPEC(basic.spc)] Liability Detail [BOTLINE]"
34570 PRINT #RTFFILE: "F|[RTFDATE] \tab Page [PAGE][TOPLINE]"
34580 PRINT #RTFFILE: "T|Detail Transaction History [RTFLINE]for "&CONM$&"[RTFLINE]"
34590 PRINT #RTFFILE: "D|[NEWCELL(editeftp.spc)] "
34600 PRINT #RTFFILE: "1| "&DHEADERS$(1)&"| "&DHEADERS$(2)&"| "&DHEADERS$(3)&"| "&DHEADERS$(4)&"| "&DHEADERS$(5)&"| "&DHEADERS$(6)&"| "&DHEADERS$(7)
34610 FOR A=1 TO UDIM(MAT DYEAR$)
34620 PRINT #RTFFILE: "2| "&DYEAR$(A)&"| "&DJURS$(A)&"| "&DREG$(A)&"| "&DTYPE$(A)&"| "&DDATE$(A)&"| "&CNVRT$("PIC(ZZZ,ZZZ,ZZ#.##-)",DAMOUNT(A))&"| "&CNVRT$("PIC(ZZZ,ZZZ,ZZ#.##-)",DBALANCE(A))
34630 NEXT A
34640 ! PRINT #RTFFILE: "3| | | | | | Total| "&CNVRT$(MASK$,SUM(MAT PPGROSS))
34650 LET RTFFILE$=FILE$(RTFFILE)
34660 OPEN #(RTFOUT:=FNGETHANDLE): "name="&ENV$("temp")&"\temp"&SESSION$&".rtf,eol=none,replace",DISPLAY,OUTPUT
34670 LET RTFOUT$=FILE$(RTFOUT)
34680 CLOSE #RTFFILE:
34690 OPEN #RTFFILE: "name="&RTFFILE$,DISPLAY,INPUT
34700 LET FNRTF(RTFFILE,ENV$("PD")&"vol002\basic.spc",RTFOUT,ENV$("PD")&"prsysc\")
34710 IF FILE(RTFFILE)>-1 THEN CLOSE #RTFFILE:
34720 IF FILE(RTFOUT)>-1 THEN CLOSE #RTFOUT:
34730 EXECUTE "sys -w -c "&FNMSEXE$("winword.exe")&" "&RTFOUT$
34740 END IF


Line 34560 refers to a "SPEC" file that contains the tab stops, font sizews etc. This looks like :

LET LMARGIN=.75
LET RMARGIN=1.0
LET TMARGIN=.50
LET BMARGIN=.50
LET ORIENTATION$="PORTRAIT"
LET PAPER$="LETTER"
LET CHECKLIST=0
LET LEFTTEXT$=""
LET NUME=0
MAT TYPES$(12)
LET TYPES$(1)="H"
LET TYPES$(2)="F"
LET TYPES$(3)="D"
LET TYPES$(4)="S"
LET TYPES$(5)="T"
LET TYPES$(6)="A"
LET TYPES$(7)="B"
LET TYPES$(8)="C"
LET TYPES$(9)="E"
LET TYPES$(10)="G"
LET TYPES$(11)="N"
LET TYPES$(12)="I"
MAT STYLES$(12)
LET STYLES$(1)="li0|ri0|fARIAL|fs14|cfBlue|tc3.25|Header"
LET STYLES$(2)="li0|ri0|fARIAL|fs8|cfBlack|tc3.25|tr6.70|Footer"
LET STYLES$(3)="li0.5|QJ|fPALATINO|ri0|fs12|tl0.5|tl1.0|tl1.5|td5.4||Data"
LET STYLES$(4)="li0.5|QC|sa1|ri0|B|fs19|fARIAL|tl0.5||tc3.25|Title Page"
LET STYLES$(5)="li0.5|QC|fARIAL|sa1|ri0|B|fs18|tl0.5||tc3.25|Heading 1"
LET STYLES$(6)="li0.25|ri0|fARIAL|B|fs17|tl0.5||tr5.4|Heading 2"
LET STYLES$(7)="li0.25|ri0|fARIAL|B|fs15|tl0.5||tr5.4|Heading 3"
LET STYLES$(8)="li0.25|ri0|fARIAL|B|fs13|tl0.5||td5.4|Heading 4"
LET STYLES$(9)="fi-0.5|td0.75|li1.0|ri0|fPALATINO|fs12|tl0.5|tl1.0|td6.0|Detail steps"
LET STYLES$(10)="fi-0.4|li1.0|ri0|ft61|fs10|fCOURIER|tl0.5|tc4.0|td5.4|Program lines"
LET STYLES$(11)="li0.5|ri0|B|fPALATINO|fs12|cfDKBLUE|tl0.5|tl1.0|tl1.5|td5.4||New Items"
LET STYLES$(12)="fi-1.25|li2.0|ri0|fPALATINO|fs12|tl2.0|Options"

MAT CELLS$(10)
rem LET CELLS$(1)="li0.5|tg0.125|c1|btrlb1|vt|hl|c1.5|btrlb1|vt|hc|"
rem LET CELLS$(2)="li0.5|tg0.125|fPALATINO|fs10|c3|btrlb1|vt|hl|c3|btrlb1|vt|hl|"
rem LET CELLS$(3)="li0.5|tg0.125|fPALATINO|fs10|c2|btrlb1|vt|hl|c2|btrlb1|vt|hl|c2|btrlb1|vt|hl|"

rem ODD numbers are headers even numbers are the following table

LET CELLS$(1)="li0.5|tg0.100|fPALATINO|fs10|trh|"
LET CELLS$(1)=CELLS$(1)&"c3.0|brtlrb1|vt|hc|sh15|"
LET CELLS$(1)=CELLS$(1)&"c3.0|brtlrb1|vt|hc|sh15|"

LET CELLS$(2)="li0.5|tg0.100|fPALATINO|fs10|"
LET CELLS$(2)=CELLS$(2)&"c3.0|brtrlb1|vt|hl|"
LET CELLS$(2)=CELLS$(2)&"c3.0|brtrb1|vt|hl|"

LET CELLS$(3)="li0.5|tg0.100|fARIAL|fs10|trh|"
LET CELLS$(3)=CELLS$(3)&"c2.0|brtrlb1|vt|hc|sh15|"
LET CELLS$(3)=CELLS$(3)&"c2.0|brtrlb1|vt|hc|sh15|"
LET CELLS$(3)=CELLS$(3)&"c2.0|brtrlb1|vt|hc|sh15|"


LET CELLS$(4)="li0.5|tg0.100|fARIAL|fs10|"
LET CELLS$(4)=CELLS$(4)&"c2.0|btrlb1|vt|hl|"
LET CELLS$(4)=CELLS$(4)&"c2.0|btrlb1|vt|hl|"
LET CELLS$(4)=CELLS$(4)&"c2.0|btrlb1|vt|hl|"

LET CELLS$(5)="li0.5|tg0.100|fARIAL|fs10|trh|"
LET CELLS$(5)=CELLS$(5)&"c1.0|brtrlb1|vt|hc|sh15|"
LET CELLS$(5)=CELLS$(5)&"c1.5|brtrlb1|vt|hc|sh15|"
LET CELLS$(5)=CELLS$(5)&"c1.5|brtrlb1|vt|hc|sh15|"
LET CELLS$(5)=CELLS$(5)&"c1.5|brtrlb1|vt|hc|sh15|"

LET CELLS$(6)="li0.5|tg0.100|fARIAL|fs10|"
LET CELLS$(6)=CELLS$(6)&"c1.0|brtrlb1|vt|hl|"
LET CELLS$(6)=CELLS$(6)&"c1.5|brtrlb1|vt|hr|"
LET CELLS$(6)=CELLS$(6)&"c1.5|brtrlb1|vt|hr|"
LET CELLS$(6)=CELLS$(6)&"c1.5|brtrlb1|vt|hr|"

LET CELLS$(7)="li0.0|tg0.100|fPALATINO|fs10|trh|"
LET CELLS$(7)=cells$(7)&"c0.5|brtrlb1|vt|hc|sh15|"
LET CELLS$(7)=cells$(7)&"c0.5|brtrlb1|vt|hc|sh15|"
LET CELLS$(7)=cells$(7)&"c0.5|brtrlb1|vt|hc|sh15|"
LET CELLS$(7)=cells$(7)&"c0.5|brtrlb1|vt|hc|sh15|"

LET CELLS$(8)="li0.0|tg0.100|fPALATINO|fs10|"
LET CELLS$(8)=cells$(8)&"c0.5|brtrlb1|vt|hc|"
LET CELLS$(8)=cells$(8)&"c0.5|brtrlb1|vt|hc|"
LET CELLS$(8)=cells$(8)&"c0.5|brtrlb1|vt|hc|"
LET CELLS$(8)=cells$(8)&"c0.5|brtrlb1|vt|hc|"

and line 34590 names another SPEC file that overrides the cells set up in BASIC.SPC. The override is named EDITEFTPS.SPC and looks like:

LET LMARGIN=1.00
LET RMARGIN=1.00
LET TMARGIN=1.00
LET BMARGIN=1.00
LET ORIENTATION$="PORTRAIT"
LET PAPER$="LETTER"
mat TYPES$(10)
LET TYPES$(1)="H"
LET TYPES$(2)="F"
LET TYPES$(3)="D"
LET TYPES$(4)="T"
LET TYPES$(5)="A"
LET TYPES$(6)="B"
LET TYPES$(7)="C"
LET TYPES$(8)="E"
LET TYPES$(9)="G"
LET TYPES$(10)="N"
MAT STYLES$(10)
LET STYLES$(1)="li0|ri0|fs12|cfBlue|tc3.25|Header"
LET STYLES$(2)="li0|ri0|fs8|cfBlack|tc3.25|Footer"
LET STYLES$(3)="li0.5|QL|ri0|fs10|tl0.5|tl1.0|tl1.5|td5.4||Data"
LET STYLES$(4)="li0.5|QC|sa1|ri0|B|fs12|tl0.5||tc3.25|Heading 1"
LET STYLES$(5)="li0.25|ri0|B|fs12|tl0.5||tr5.4|Heading 2"
LET STYLES$(6)="li0.25|ri0|B|fs11|tl0.5||tr5.4|Heading 3"
LET STYLES$(7)="li0.25|ri0|B|fs10|tl0.5||td5.4|Heading 4"
LET STYLES$(8)="fi-0.5|QL|td0.75|li1.0|ri0|fs12|tl0.5|tl1.0|td6.0|Detail steps"
LET STYLES$(9)="fi-0.4|li1.0|ri0|ft61|fs10|fCOURIER|tl0.5|tc4.0|td5.4|Program lines"
LET STYLES$(10)="li0.5|ri0|B|fs12|cfDKBLUE|tl0.5|tl1.0|tl1.5|td5.4||New Items"
MAT CELLS$(4)


LET CELLS$(1)="li0.50|tg0.050|trrh0.22|fPALATINO|fs10|trh|"
LET CELLS$(1)=CELLS$(1)&"c0.5|brtlrb1|vt|hc|sh15|"
LET CELLS$(1)=CELLS$(1)&"c0.60|brtlrb1|vt|hc|sh15|"
LET CELLS$(1)=CELLS$(1)&"c0.75|brtlrb1|vt|hc|sh15|"
LET CELLS$(1)=CELLS$(1)&"c0.85|brtlrb1|vt|hc|sh15|"
LET CELLS$(1)=CELLS$(1)&"c1.10|brtlrb1|vt|hc|sh15|"
LET CELLS$(1)=CELLS$(1)&"c1.25|brtlrb1|vt|hc|sh15|"
LET CELLS$(1)=CELLS$(1)&"c1.25|brtlrb1|vt|hc|sh15|"


LET CELLS$(2)="li0.50|tg0.050|trrh0.22|fPALATINO|fs10|"
LET CELLS$(2)=CELLS$(2)&"c0.5|brtlrb1|vt|hl|"
LET CELLS$(2)=CELLS$(2)&"c0.60|brtlrb1|vt|hl|"
LET CELLS$(2)=CELLS$(2)&"c0.75|brtlrb1|vt|hl|"
LET CELLS$(2)=CELLS$(2)&"c0.85|brtlrb1|vt|hl|"
LET CELLS$(2)=CELLS$(2)&"c1.10|brtlrb1|vt|hl|"
LET CELLS$(2)=CELLS$(2)&"c1.25|brtlrb1|vt|hr|"
LET CELLS$(2)=CELLS$(2)&"c1.25|brtlrb1|vt|hr|"

LET CELLS$(3)="li0.5|tg0.010|fs10|"
LET CELLS$(3)=CELLS$(3)&"c3.0|vt|hl|"
LET CELLS$(3)=CELLS$(3)&"c1.5|brrl1|brt2|brbd2|vt|hr|"

LET CELLS$(4)="li0.5|tg0.100|fARIAL|fs10|"
LET CELLS$(4)=CELLS$(4)&"c3.0|btrlb1|fCOURIER|vt|hl|"
LET CELLS$(4)=CELLS$(4)&"c0.5|fs8|btb1|vt|hc|"
LET CELLS$(4)=CELLS$(4)&"c0.5|btlb1|fPALATINO|vt|hc|"
LET CELLS$(4)=CELLS$(4)&"c1|fs10|btrlb1|fARIAL|vt|hr|"
LET CELLS$(4)=CELLS$(4)&"c1|btrlb1|vt|hr|"
LET CELLS$(4)=CELLS$(4)&"c1|btrlb1|vt|hr|"
LET CELLS$(4)=CELLS$(4)&"c1|btrlb1|vt|hr|"
LET CELLS$(4)=CELLS$(4)&"c1|btrlb1|vt|hr|"
LET CELLS$(4)=CELLS$(4)&"c1|btrlb1|vt|hr|"

This may seem complicated, but once you get one SPC file set-up changing a few parameters is quick and easy and you can then create tables in an RTF document very quickly. Your RTF reader (Word or Open Office) can then easily manipulate the list by sorting the columns within the reader.

The RTFLIB library has a few improvements since that last time that I showed it at a conference. These include the ability to use user replaceable parameters. If anyone is interested let me know and I'll explain how it works.

FNGeorge
Post Reply