Page 1 of 1

Multi dim. array challenge didn't work

Posted: Sat Jan 21, 2017 10:58 pm
by Marc Venken
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 :wink: 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. :oops:

So here I'm...

What I want to change

Code: Select all | Expand


   @ 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: Select all | Expand


   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

 

Re: Multi dim. array challenge didn't work

Posted: Sun Jan 22, 2017 7:38 am
by Antonio Linares
Not sure if this is what you are looking for:

Code: Select all | Expand

#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

Re: Multi dim. array challenge didn't work

Posted: Sun Jan 22, 2017 9:05 am
by Marc Venken
That was it !

Thank you...

Re: Multi dim. array challenge didn't work

Posted: Sun Jan 22, 2017 10:16 am
by nageswaragunupudi
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: Select all | Expand


   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: Select all | Expand


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.

Re: Multi dim. array challenge didn't work

Posted: Sun Jan 22, 2017 1:03 pm
by Marc Venken
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:

Re: Multi dim. array challenge didn't work

Posted: Sun Jan 22, 2017 1:26 pm
by nageswaragunupudi
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.

Re: Multi dim. array challenge didn't work

Posted: Sun Jan 22, 2017 10:10 pm
by nageswaragunupudi
Transposing Arrays:


Code: Select all | Expand

  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: Select all | Expand


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 ]
 

Re: Multi dim. array challenge didn't work

Posted: Fri Jan 27, 2017 3:38 am
by rhlawek
Is there a sample available that shows using all the array elements, in particular best practices/allowed values for Exprn and cSortOrder?

Robb