Multi dim. array challenge didn't work

Multi dim. array challenge didn't work

Postby Marc Venken » 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 :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 view

   @ 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 view

   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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Multi dim. array challenge didn't work

Postby Antonio Linares » Sun Jan 22, 2017 7:38 am

Not sure if this is what you are looking for:

Code: Select all  Expand view
#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
Antonio Linares
Site Admin
 
Posts: 42068
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Multi dim. array challenge didn't work

Postby Marc Venken » Sun Jan 22, 2017 9:05 am

That was it !

Thank you...
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Multi dim. array challenge didn't work

Postby nageswaragunupudi » 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: Select all  Expand view

   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 view

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
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Multi dim. array challenge didn't work

Postby Marc Venken » Sun Jan 22, 2017 1: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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Multi dim. array challenge didn't work

Postby nageswaragunupudi » Sun Jan 22, 2017 1: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
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Multi dim. array challenge didn't work

Postby nageswaragunupudi » Sun Jan 22, 2017 10:10 pm

Transposing Arrays:


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

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
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Multi dim. array challenge didn't work

Postby rhlawek » Fri Jan 27, 2017 3: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
User avatar
rhlawek
 
Posts: 194
Joined: Sun Jul 22, 2012 7:01 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 57 guests