Multidimentional array with xBrowse

Multidimentional array with xBrowse

Postby Patrick Mast » Tue Aug 05, 2008 1:32 pm

Hi,

How can I browse an array like this with xBrowse:
Code: Select all  Expand view  RUN
aArray:={{"Row1-Col1","Row1-Col2","Row1-Col3"},;
         {"Row2-Col1","Row2-Col2","Row2-Col3"},;
         {"Row3-Col1","Row3-Col2","Row3-Col3"},;
         {"Row4-Col1","Row4-Col2","Row4-Col3"}}
Thanks.

Patrick
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Postby nageswaragunupudi » Tue Aug 05, 2008 2:35 pm

Code: Select all  Expand view  RUN
local ownd, oBrw
local aArray:={{"Row1-Col1","Row1-Col2","Row1-Col3"},;
         {"Row2-Col1","Row2-Col2","Row2-Col3"},;
         {"Row3-Col1","Row3-Col2","Row3-Col3"},;
         {"Row4-Col1","Row4-Col2","Row4-Col3"}}

DEFINE WINDOW oWnd

@ 0,0 XBROWSE oBrw ;
HEADERS 'One', 'Two', 'Three' ;
OF oWnd ARRAY aArray AUTOCOLS

oBrw:CreateFromCode()
oWnd:oClient := oBrw
ACTIVATE WINDOW ownd

Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby Patrick Mast » Tue Aug 05, 2008 2:39 pm

nageswaragunupudi wrote:
Code: Select all  Expand view  RUN
local ownd, oBrw
local aArray:={{"Row1-Col1","Row1-Col2","Row1-Col3"},;
         {"Row2-Col1","Row2-Col2","Row2-Col3"},;
         {"Row3-Col1","Row3-Col2","Row3-Col3"},;
         {"Row4-Col1","Row4-Col2","Row4-Col3"}}

DEFINE WINDOW oWnd

@ 0,0 XBROWSE oBrw ;
HEADERS 'One', 'Two', 'Three' ;
OF oWnd ARRAY aArray AUTOCOLS

oBrw:CreateFromCode()
oWnd:oClient := oBrw
ACTIVATE WINDOW ownd


Thank you.

How can I do the same but with the ADD TO oBrw HEADER "MyCol" DATA Array[x][y] command?

You see, I want to have control over how the array is being displayed in the browse. maybe i want Colunmt 1 in UPPPER, and the value of aArray[x][4] in the 3rd Column etc..

Patrick
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Postby nageswaragunupudi » Tue Aug 05, 2008 2:47 pm

We can reorder the columns and choose particular columns in single command:
Code: Select all  Expand view  RUN
@ 0,0 XBROWSE oBrw ;
    COLUMNS 3, 2, 4 ;
    HEADERS <a>, <b>, <c> ;
    OF oWnd ;
    ARRAY aArray   // should not use AUTOCOLS now

// to use ADD TO oBrw

@ 0,0 XBROWSE oBrw OF oWnd ARRAY aArray  // can also contain some columns

ADD TO oBrw ARRAY ELEMENT 5 HEADER <header> PICTURE <pic> ......

// or for more control

ADD TO oBrw DATA oBrw:aRow[ <nCol> ]  * 10 + 20 ;
   HEADER <header> PICTURE '99999'  ....


We can use all the above commands for the same browse
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby Patrick Mast » Tue Aug 05, 2008 2:53 pm

nageswaragunupudi wrote:We can reorder the columns and choose particular columns in single command:
Code: Select all  Expand view  RUN
@ 0,0 XBROWSE oBrw ;
    COLUMNS 3, 2, 4 ;
    HEADERS <a>, <b>, <c> ;
    OF oWnd ;
    ARRAY aArray   // should not use AUTOCOLS now

// to use ADD TO oBrw

@ 0,0 XBROWSE oBrw OF oWnd ARRAY aArray  // can also contain some columns

ADD TO oBrw ARRAY ELEMENT 5 HEADER <header> PICTURE <pic> ......

// or for more control

ADD TO oBrw DATA oBrw:aRow[ <nCol> ]  * 10 + 20 ;
   HEADER <header> PICTURE '99999'  ....


We can use all the above commands for the same browse

Thanks again ;-)
So, this is a kind different than we'd use to do with WBrowse. We had a <n> variabe that holds the counter for the array, like this:

Code: Select all  Expand view  RUN
oBrw:bLine     :={Str(aArray[n][1]),aArray[n][4]*2} etc...
oBrw:bGoTop    :={||n:=1}
oBrw:bGoBottom :={||n:=Len(aArray[1])}
oBrw:bSkip     :={|nSkip, nOld| nOld := n, n += nSkip,n := Max( 1, Min( n, Len(aArray[1]) ) ), n - nOld}
oBrw:bLogicLen :={||Len(aArray[1]) }
oBrw:cAlias    :="Array"  // We need a non empty cAlias !


Just need to RE-learn how to use Browse with xBrowse :)

Patrick
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Postby Enrico Maria Giordano » Tue Aug 05, 2008 2:55 pm

This is a way more similar to the other browses:

Code: Select all  Expand view  RUN
#include "Fivewin.ch"
#include "XBrowse.ch"


FUNCTION MAIN()

    LOCAL oDlg, oBrw

    LOCAL aArray := { { "Row1-Col1", "Row1-Col2", "Row1-Col3" },;
                      { "Row2-Col1", "Row2-Col2", "Row2-Col3" },;
                      { "Row3-Col1", "Row3-Col2", "Row3-Col3" },;
                      { "Row4-Col1", "Row4-Col2", "Row4-Col3" } }

    LOCAL nCur := 1

    DEFINE DIALOG oDlg;
           SIZE 800, 600

    @ 0, 0 XBROWSE oBrw FIELDS aArray[ nCur, 1 ],;
                               aArray[ nCur, 2 ],;
                               aArray[ nCur, 3 ];
           HEADERS "COL1", "COL2", "COL3";
           ARRAY aArray

    oBrw:CreateFromCode()

    oBrw:bGoTop    = { || nCur := 1 }
    oBrw:bGoBottom = { || nCur := Len( aArray ) }
//    oBrw:bBof      = { || nCur = 1 }
//    oBrw:bEof      = { || nCur = Len( aArray ) }
//    oBrw:bKeyCount = { || Len( aArray ) }
//    oBrw:bPastEof  = { || nCur > Len( aArray ) }
    oBrw:bBookMark = { | nBkm | If( nBkm == nil, nCur, nCur := nBkm ) }
    oBrw:bSkip     = { | nSkip | Skipper( aArray, @nCur, nSkip ) }

    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:SetControl( oBrw );
             CENTER

    RETURN NIL


STATIC FUNCTION SKIPPER( aArray, nCur, nSkip )

    LOCAL nOld := nCur

    DEFAULT nSkip := 1

    nCur += nSkip

    IF nCur > LEN( aArray ); nCur = LEN( aArray ); ENDIF
    IF nCur < 1; nCur = 1; ENDIF

    RETURN nCur - nOld


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Patrick Mast » Tue Aug 05, 2008 2:59 pm

Enrico Maria Giordano wrote:This is a way more similar to the other browses:

Thank you Enrico! Looks very simular now :)

Antonio, which is the "Standard" xBrowse way to browse multidimentional arrays?

Patrick
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 61 guests