for. Mr. Rao

for. Mr. Rao

Postby mgsoft » Sun Apr 03, 2011 1:10 pm

Mr. Rao,

Hope you are well from hospital.

I would like to know which is the best way to do the following with xBrose:

First, Load all the records to a dbf to an array(), but use the inverse order (first the last record)

Second, xBrowse certain fields of the dbf loaded into the array.


Thank you very much.
Saludos,

Eduardo
User avatar
mgsoft
 
Posts: 422
Joined: Mon Aug 17, 2009 12:18 pm
Location: España

Re: for. Mr. Rao

Postby Richard Chidiak » Sun Apr 03, 2011 3:21 pm

Mgsoft

First me byst wishes to mr Rao, i did not know he was at hospital. Hope he is ok and we shall see him soon here in this forum.

As per your questions , i do this frequently

1. Load dbf into an array

while ! eof()
aadd(TVISU,{field1,file2,filed3,ctod(field4) ....}) // You can also transform field dates ..etc

Browsing the array

This is a sample where i browse certain fields of the dbf , if you want them all remove the columns syntax

REDEFINE XBROWSE oBrw ID 201 OF ODLG ;
COLUMNS 33,34,4,22,31,23,6,7,8,24,21 ;
HEADERS "Date" + CRLF + "Création","Style", "N°" + CRLF + "Devis","Client","Date" + CRLF + "Impression","Téléphone","Total" + CRLF + "HT","Total" + CRLF + "TTC","Total" + CRLF + "Acomptes",;
" ","Taux" + CRLF + "Tva";
FOOTERS ;
FONT aFont ;
COLORS {|| { CLR_BLUE, CLR_WHITE } } ;
COLSIZES asize ;
array TVISU lines AUTOSORT

In order to read them from last to first

WITH OBJECT oBrw:aCols["Date" + CRLF + "Création"] // example for the first column , i never address acols[1] or whatever, always address the column header definition
:cOrder := If( corder == 'A', 'D', 'A' )
:SetOrder()
END

Hth

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: for. Mr. Rao

Postby Enrico Maria Giordano » Sun Apr 03, 2011 3:29 pm

Richard Chidiak wrote:i did not know he was at hospital.


Me neither. My best wishes to Rao!

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

Re: for. Mr. Rao

Postby Rick Lipkin » Sun Apr 03, 2011 4:25 pm

My Best to Rao as well !!

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: for. Mr. Rao

Postby hag » Sun Apr 03, 2011 6:11 pm

No questions. Just best wishes for a healthy return to the forum.
Thank you
Harvey
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California

Re: for. Mr. Rao

Postby nageswaragunupudi » Mon Apr 04, 2011 7:03 am

Sincere thanks to all for the good wishes. I am ok now and back at work. There are too many things to catch up though.

Reply to the original post by mgsoft:

This can be done in many ways. This is one approach.
Code: Select all  Expand view
#include "FiveWin.Ch"
#include "ord.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//

function Main()

   local oWnd, oBrw, aData, cFieldList

    SET DATE ITALIAN
    SET CENTURY ON
    SET DELETED ON
    RDDSETDEFAULT( "DBFCDX" )

   USE CUSTOMER NEW SHARED READONLY
   SET FILTER TO !DELETED()
   GO TOP

   // If all columns are required, comment out the next line.
   cFieldList  := [ "First", "City", "HireDate", "Age", "Salary" ]
   aData       := CUSTOMER->( ReadIntoArray( @cFieldList ) )

   DEFINE WINDOW oWnd
   @ 0,0 XBROWSE oBrw OF oWnd AUTOCOLS ARRAY aData HEADERS &cFieldList CELL LINES
   oBrw:CreateFromCode()
   oWnd:oClient   := oBrw
   ACTIVATE WINDOW oWnd
   CLOSE DATA

return (0)

//----------------------------------------------------------------------------//

static function ReadIntoArray( cList )

   local bLine, aData, i, n

   if Empty( cList )
      n        := FCount()
      cList    := '"'  + FieldName( 1 ) + '"'
      for i := 2 to n
         cList += ',"' + FieldName( i ) + '"'
      next
   endif

   bLine    := &( "{||{" + StrTran( StrTran( cList, "'", '' ), '"', '' ) + "}}" )
   aData    := Array( n := OrdKeyCount() )

   GO TOP
   DBEVAL( { || aData[ n-- ] := Eval( bLine ) } )
   GO TOP

return aData

//----------------------------------------------------------------------------//
 

Note of the filter "SET FILTER TO !DELETED()" :

This filter is necessary to obtain accurate results from the functions OrdKeyCount(), OrdKeyGoTo(), OrdKeyNum(). This accuracy is desirable for XBrowse and also for the function I used in this program.

This filter is Optimized by DBFCDX if there is a tag on the expression DELETED(). It is a good practice to add one TAG to every large DBF like:
Code: Select all  Expand view
INDEX ON DELETED() TAG DELETED


Another major advantage of having this index and setting this filter is that the frequently exprienced slownness in browsing large DBF files with many deleted records is avoided.
Regards

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

Re: for. Mr. Rao

Postby nageswaragunupudi » Mon Apr 04, 2011 7:10 am

oBrw:aCols["Date" + CRLF + "Création"] // example for the first column , i never address acols[1] or whatever, always address the column header definition

This is a good practice because the order of the columns can be changed by the user at runtime, but the syntax appears inaccurate.

This can be written as oBrw:oCol( "DateCreation" ) or oBrw:DateCreation.
XBrowse matches "DateCreation" with the header after sripping CRLF and spaces. "DateCreation" matches header "Date" + CRLF + "Creation" or "Date Creation".
Regards

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

Re: for. Mr. Rao

Postby Richard Chidiak » Mon Apr 04, 2011 7:38 am

Thank you M. Rao

Always something to learn from your great valuable posts.

I will adapt my code,

Best regards

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: for. Mr. Rao

Postby mgsoft » Mon Apr 04, 2011 8:18 am

Thank you very much to all.

Glad to see that Mr. Rao is Ok.

I would like to know which is the best way for xBrowse to change order (starting from the end of the DBF and the array).

Thank you.
Saludos,

Eduardo
User avatar
mgsoft
 
Posts: 422
Joined: Mon Aug 17, 2009 12:18 pm
Location: España

Re: for. Mr. Rao

Postby nageswaragunupudi » Mon Apr 04, 2011 8:36 am

I would like to know which is the best way for xBrowse to change order (starting from the end of the DBF and the array).

Can you please elaborate your question in greater detail?
Regards

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

Re: for. Mr. Rao

Postby mgsoft » Mon Apr 04, 2011 8:49 am

Yes, sure.

I have the following database:

Code Company
1 ABC Video, S.A.
2 ARANGIO RUIZ, S.L.
3 SANZ CONSTRUCCIONES, C.B.
4 ZAPATA DEL RIO, S.L.

I want the xBrowse to be sorted in the inverse order:

4 ZAPATA DEL RIO, S.L.
3 SANZ CONSTRUCCIONES, C.B.
2 ARANGIO RUIZ, S.L.
1 ABC VIDEO, S.A.


So at the beginning of the xBrowse I get the latest companies.


Thank you.
Saludos,

Eduardo
User avatar
mgsoft
 
Posts: 422
Joined: Mon Aug 17, 2009 12:18 pm
Location: España

Re: for. Mr. Rao

Postby nageswaragunupudi » Mon Apr 04, 2011 12:46 pm

Very simple.
Use OrdDescend() function.
Image

Here is the sample program:
Code: Select all  Expand view
#include "FiveWin.Ch"
#include "ord.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//

function Main()

   local oWnd, oBrw, aData, cFieldList

   SET DELETED ON
   RDDSETDEFAULT( "DBFCDX" )

   CreateTestDBF()

   USE COMPANY SHARED
   SET ORDER TO TAG CODE
   OrdDescend( 'CODE', nil, .t. )
   GO TOP

   DEFINE WINDOW oWnd
   @ 0,0 XBROWSE oBrw OF oWnd AUTOCOLS ALIAS 'COMPANY' CELL LINES
   oBrw:CreateFromCode()
   oWnd:oClient   := oBrw
   ACTIVATE WINDOW oWnd
   CLOSE DATA

return (0)

//----------------------------------------------------------------------------//

static function CreateTestDBF()

   field CODE, COMPANY

   local n
   local aData := { ;
      {  1,  "ABC Video, S.A." },           ;
      {  2,  "ARANGIO RUIZ, S.L." } ,       ;
      {  3,  "SANZ CONSTRUCCIONES, C.B." }, ;
      {  4,  "ZAPATA DEL RIO, S.L." }       }
   local aCols := { ;
      {  "CODE",     "N",  2,    0  }, ;
      {  "COMPANY",  "C", 30,    0  }  }

   DBCREATE( "COMPANY", aCols )
   USE COMPANY EXCLUSIVE
   for n := 1 to Len( aData )
      DBAPPEND()
      FieldPut( 1, aData[ n ][ 1 ] )
      FieldPut( 2, aData[ n ][ 2 ] )
   next n
   INDEX ON CODE TAG CODE
   INDEX ON UPPER( COMPANY ) TAG COMPANY
   CLOSE COMPANY

return nil

//----------------------------------------------------------------------------//
 
Regards

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


Return to FiveWin for Harbour/xHarbour

Who is online

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