//$MENU window=comparison;popup=groups;insertafter=create groups from database field;name=Show group legend integer i,j,r,g,b; integer groupinuse[],groupcount,groups[]; INDEX groupidx; string fieldlist,fieldname,st,st2; DIALOG dlg; if not(CmpIsPresent) then CmpAttach; if not(CmpIsPresent) then { Message("No comparison selected"); stop; } for i=1 to DbGetFieldCount do fieldlist=fieldlist+DbGetFieldName(i)+" "; fieldname=fieldlist;fieldname=splitstring(fieldname," "); DlgAddText(dlg,"Select the field you want to use:",15,15,200,15); DlgAddList(dlg,fieldlist,fieldname,15,40,150,150,"LIST"); if not(DlgShow(dlg,"Group legend",300,300)) then stop; for i=1 to 100 do groupinuse[i]=0; for i=1 to CmpGetEntryCount do { j=CmpGetGroup(i); groupinuse[j]=1; } for i=1 to 100 do if groupinuse[i] then { groupcount=groupcount+1; groups[groupcount]=i; } PrnStartScreen(17,groupcount*0.8+2); PrnTextstyle("arial",0.4,0,0,0,0); for i=1 to groupcount do { CmpGroupColor(groups[i],r,g,b); PrnFillRect(1,i*0.8+0.1,2,i*0.8+0.7,r,g,b); IdxReset(groupidx);st=""; for j=1 to CmpGetEntryCount do if CmpGetGroup(j)=groups[i] then { st2=DbGetField(CmpGetEntryKey(j),fieldname); if IdxGet(groupidx,st2)=0 then { if st<>"" then st=st+", "; st=st+st2; IdxSet(groupidx,st2,1); } PrnText(2.2,i*0.8+0.5,st); } } PrnEnd;