FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Multi dim. array challenge didn't work
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Multi dim. array challenge didn't work
Posted: Sat Jan 21, 2017 10:58 PM
I challenged myself i fine tuning some code :

I wanted to convert this browse for easy reading and changing data, so that I don't need to count the fields in the source :-) before editing.

I can do it with 3 times a single array's in a for next loop, but I wanted a chalenge...

Do it with Multi array and aEval, since I see aEval and Dbeval very ofthen.

I have to admit, I'ts not working and a sample I haven't found. :-)

So here I'm...

What I want to change

Code (fw): Select all Collapse
   @ 590,10 XBROWSE oBrw4 SIZE 1420,220 ;
      PIXEL OF oWnd font oFont3;
      DATASOURCE "MASTER" ;
      COLUMNS "Selection","Code","Naam","lev_naam","lev_ref","fab_naam","fab_ref","Pagina","cat_main","Cat_sub1","Bruto","brutoKor","Geldigvan","geldigtot","Kleuren","Maten","picture","memo","filename" ;
      HEADERS 'Sel',"Code",'Naam',"Lever","levCode","Fabrikant","FabCode","Pag",'Cat_Main',"Cat_Sub","Bruto","Kor","Van","Tot","Kleuren","Maten","picture","memo","Database";
      COLSIZES 30,60,180,60,60,60,60,40,60,60,40,40,60,60,80,80,80,80,80;
      autosort CELL LINES FOOTERS NOBORDER fastedit;
      ON CHANGE ( ;
         If( Empty( oBrw4:SelectedCol():cOrder ), ;
           ( oBrw4:SelectedCol():SetOrder(), oBrw4:seek(""), oBrw4:Refresh() ), ;
         nil ) )


into something like this :

Code (fw): Select all Collapse
   aSpec :=  { ;
   {  1, "Selection","Sel"     , 30 }, ;
   {  2, "Code",  "Code"  , 60 }, ;
   {  3, "Naam",   "Naam"  , 180 }, ;
   enz....

//AEVAL( aSpec  , {|a| AINS( aFields, 3, 'x' ) })
//AEVAL( aSpec  , {|a| AINS( aHeaders, 4, 'x' ) })
//AEVAL( aSpec  , {|a| AINS( aSizes, 4, 'x' ) })

   @  90,20 XBROWSE oBrw SIZE 900,-20 PIXEL OF oDlg ;
      DATASOURCE "MASTER" ;
      COLUMNS aFields;
      headers aHeaders;
      colsize aSizes;
      AUTOSORT ;
      LINES NOBORDER
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Multi dim. array challenge didn't work
Posted: Sun Jan 22, 2017 07:38 AM
Not sure if this is what you are looking for:

Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()

   local oDlg, oBrw

   local aFields := {}, aHeaders := {}, aSizes := {}
   local aSpec :=  { ;
   { "Selection", "Sel" ,  30 }, ;
   { "Code",      "Code",  60 }, ;
   { "Naam",      "Naam", 180 } }

   AEval( aSpec, { | a | AAdd( aFields, a[ 1 ] ),;
                         AAdd( aHeaders, a[ 2 ] ),;
                         AAdd( aSizes, a[ 3 ] ) } )

   DEFINE DIALOG oDlg SIZE 210, 210

   @  10, 10 XBROWSE oBrw SIZE 200, 200 PIXEL OF oDlg ;
      DATASOURCE aSpec ;
      COLUMNS aFields;
      HEADERS aHeaders;
      COLSIZES aSizes;
      AUTOSORT ;
      LINES NOBORDER

   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT oBrw:CreateFromCode()

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: Multi dim. array challenge didn't work
Posted: Sun Jan 22, 2017 09:05 AM

That was it !

Thank you...

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Multi dim. array challenge didn't work
Posted: Sun Jan 22, 2017 10:16 AM
Good.
But there is no need to take all this trouble.
Xbrowse does all this work internally for us without writing any code.

This is the simpler way:

Code (fw): Select all Collapse
   aSpec :=  { ;
   {  "Selection",   "Sel",   nil,  30 }, ;
   {  "Code",        "Code",  nil,  60 }, ;
   {  "Naam",        "Naam",  nil, 180 }, ;
   enz....


   @  90,20 XBROWSE oBrw SIZE 900,-20 PIXEL OF oDlg ;
      DATASOURCE "MASTER" ;
      COLUMNS aSpec ;
      AUTOSORT ;
      LINES NOBORDER


Xbrowse internally extracts datas, headers, pictures, columnwidths, etc from your multi-dim array internally, without your spending time on writing code like above.

This is the format of aSpec:

Code (fw): Select all Collapse
aSpec := { ;
   { cData/Exprn1,  [cHeader1],  [cPicture1], [nWidth1], [nAlign1], [cSortorder1] }, ;
   { cData/Exprn2,  [cHeader2],  [cPicture2], [nWidth2], [nAlign2], [cSortorder2] }, ;
   ....
   { cData/ExprnN,  [cHeaderN],  [cPictureN], [nWidthN], [nAlignN], [cSortorderN] }, ;
       
// Square Brackets indicate Optional values
// You need to fill all columns of each array element.


XBrowse is made to save programmer's time.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: Multi dim. array challenge didn't work
Posted: Sun Jan 22, 2017 01:03 PM

Very nice. Changed my code...

I'm sure that I can reduce my code of my first project with more that 60 % once I have more knowledge of FWH! :lol:

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Multi dim. array challenge didn't work
Posted: Sun Jan 22, 2017 01:26 PM

Yes and even more.

We suggest you post some of your code and we keep suggesting the best ways to make it simpler, safer and better.

Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Multi dim. array challenge didn't work
Posted: Sun Jan 22, 2017 10:10 PM
Transposing Arrays:


Code (fw): Select all Collapse
   aSpec :=  { ;
   {  1, "Selection","Sel"     , 30 }, ;
   {  2, "Code",  "Code"  , 60 }, ;
   {  3, "Naam",   "Naam"  , 180 }, ;
   enz....


You wanted all columns 1, 2, 3, 4 into 4 arrays

One way is to Transpose this array. Means convert rows as columns and columns as rows.

Code (fw): Select all Collapse
aNew := ArrTranspose( aSpec )

/*
Now aNew is :
{ ;
   { 1, 2, 3, .... }, ;
   { "Selection", "Code", "Naam", ... }, ;
   { "Sel", "Code", "Naam", ... }, ;
   { 30, 60, 180, ... } ;
}
*/
aData := aNew[ 2 ]
aHeaders := aNew[ 3 ]
aWidths   := aNew[ 4 ]
Regards



G. N. Rao.

Hyderabad, India
Posts: 195
Joined: Sun Jul 22, 2012 07:01 PM
Re: Multi dim. array challenge didn't work
Posted: Fri Jan 27, 2017 03:38 AM

Is there a sample available that shows using all the array elements, in particular best practices/allowed values for Exprn and cSortOrder?

Robb

Continue the discussion