Multi dim. array challenge didn't work

Post Reply
User avatar
Marc Venken
Posts: 1485
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Multi dim. array challenge didn't work

Post 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

 
Marc Venken
Using: FWH 23.08 with Harbour
User avatar
Antonio Linares
Site Admin
Posts: 42521
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 76 times
Contact:

Re: Multi dim. array challenge didn't work

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Marc Venken
Posts: 1485
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Multi dim. array challenge didn't work

Post by Marc Venken »

That was it !

Thank you...
Marc Venken
Using: FWH 23.08 with Harbour
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Multi dim. array challenge didn't work

Post 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
Marc Venken
Posts: 1485
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Multi dim. array challenge didn't work

Post 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:
Marc Venken
Using: FWH 23.08 with Harbour
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Multi dim. array challenge didn't work

Post 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Multi dim. array challenge didn't work

Post 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 ]
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
rhlawek
Posts: 194
Joined: Sun Jul 22, 2012 7:01 pm

Re: Multi dim. array challenge didn't work

Post 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
Post Reply