FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour use fw_arraytodbf with conditions
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
use fw_arraytodbf with conditions
Posted: Sat Sep 17, 2022 10:35 AM
I have an array previously built from a txt file, in this array as the first field there is a date field, I have to convert this array into a dbf file all records if the date field (dUltimaData) is greater than the last passed date

oTemp:= TDatabase():Open( , cPath+"LOTTO", "DBFCDX", .T. )
oTemp:gobottom()
dUltimaData:=oTemp:data


olotto2:= TDatabase():Open( , cPath+"STORICO", "DBFCDX", .T. )
SET DELETED ON
olotto2:setorder(0)
oLotto2:gotop()

//FW_ArrayToDBF( aData, cFieldList, bProgress, lOverWrite, lRecallDeleted, bTrigger )


oLotto2:fw_ArrayToDBF( aData,,bProgress) // how insert conditions ?

I need to create it because when I update the archive the old procedure deletes all the archive and re-insert all the records while it should only add the new records which then if the extraction is not updated is only one the records are only 11 and therefore the end user does not have to wait a long time to update the archive

I tried to create a new array with only the records need to me

oTemp:= TDatabase():Open( , cPath+"LOTTO", "DBFCDX", .T. )
oTemp:gobottom()
dUltimaData:=oTemp:data

For n= 1 to len(aData)
If ctod(aData[1][n]) > dUltimaData
AaDd(aNewData,{aData[1][n],;
aData[2][n],;
aData[3][n],;
aData[4][n],;
aData[5][n],;
aData[6][n],;
aData[7][n]})
Endif
Next

but make me error

Code (fw): Select all Collapse
Error occurred at: 17-09-2022, 12:56:24
   Error description: Error BASE/1132  Bound error: array access
   Args:
     [   1] = A   {"07/01/1939","BA","58","22","47","49","69"} length: 7
     [   2] = N   8


wich is 8 ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: use fw_arraytodbf with conditions
Posted: Sun Sep 18, 2022 01:17 PM
Code (fw): Select all Collapse
For n= 1 to len(aData)
If ctod(aData[1][n]) > dUltimaData
AaDd(aNewData,{aData[1][n],;
aData[2][n],;
aData[3][n],;
aData[4][n],;
aData[5][n],;
aData[6][n],;
aData[7][n]})
Endif
Next

It should be aData[ n, nCol ] or aData[ n ][ nCol ] but not aData[ nCol ][ n ]
When in the for loop "n" exceeds 7, you get this error.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: use fw_arraytodbf with conditions
Posted: Sun Sep 18, 2022 06:01 PM
Inserting new records:

For testing, I have used a small portion of the "storico.txt"

We already have some data in STORICO.DBF and now we will try to insert new records.



Code (fw): Select all Collapse
#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local cText, aData, aNew, dMaxDate

   cText    := HB_MEMOREAD( "storico.txt" )
   cText    := FW_ALLTRIM( cText )
   cText    := StrTran( cText, CRLF, Chr( 10 ) )

   aData    := HB_ATokens( cText, Chr( 10 ) )

   // for purpose of testing we take a small portion of the Data
   ASIZE( aData, 24)
   //

   AEval( aData, { |c,i| aData[ i ] := HB_ATokens( c, Chr( 9 ) ) } )
   AEval( aData, { |a,i| a[ 1 ] := uCharToVal( a[ 1 ], "D" ) } )

   USE STORICO NEW VIA "DBFCDX" EXCLUSIVE
   XBROWSER ALIAS() SHOW RECID

   DBGOBOTTOM()
   dMaxDate := FIELD->DATA

   aNew     := {}
   AEval( aData, { |a| If( a[ 1 ] > dMaxDate, AAdd( aNew, a ), ) } )
   FW_ArrayToDbf( anew )

   XBROWSER ALIAS() SHOW RECID
   CLOSE DATA

return nil


Regards



G. N. Rao.

Hyderabad, India
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: use fw_arraytodbf with conditions
Posted: Mon Sep 19, 2022 07:10 AM
THANKS RAO
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: use fw_arraytodbf with conditions - RESOLVED
Posted: Mon Sep 19, 2022 11:04 AM

Rao,
on my test I have the dMaxDate "10/09/2022"
and on storico.txt I arrive until 2022/09/17
when I execute

aNew := {}
AEval( aData, { |a| If( a[ 1 ] > dMaxDate, AAdd( aNew, a ), ) } )
oStorico:FW_ArrayToDbf( anew )

XBROWSER oStorico SHOW RECID

I not see any records

why ?

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: use fw_arraytodbf with conditions
Posted: Tue Sep 20, 2022 08:17 AM
nageswaragunupudi wrote:Inserting new records:

For testing, I have used a small portion of the "storico.txt"

We already have some data in STORICO.DBF and now we will try to insert new records.



Code (fw): Select all Collapse
#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local cText, aData, aNew, dMaxDate

   cText    := HB_MEMOREAD( "storico.txt" )
   cText    := FW_ALLTRIM( cText )
   cText    := StrTran( cText, CRLF, Chr( 10 ) )

   aData    := HB_ATokens( cText, Chr( 10 ) )

   // for purpose of testing we take a small portion of the Data
   ASIZE( aData, 24)
   //

   AEval( aData, { |c,i| aData[ i ] := HB_ATokens( c, Chr( 9 ) ) } )
   AEval( aData, { |a,i| a[ 1 ] := uCharToVal( a[ 1 ], "D" ) } )

   USE STORICO NEW VIA "DBFCDX" EXCLUSIVE
   XBROWSER ALIAS() SHOW RECID

   DBGOBOTTOM()
   dMaxDate := FIELD->DATA

   aNew     := {}
   AEval( aData, { |a| If( a[ 1 ] > dMaxDate, AAdd( aNew, a ), ) } )
   FW_ArrayToDbf( anew )

   XBROWSER ALIAS() SHOW RECID
   CLOSE DATA

return nil







Rao I have problem

give me a xbrowse empty

Please try this test
Code (fw): Select all Collapse
#include "fivewin.ch"

REQUEST DBFCDX


FUNCTION Main()

   // PUBLIC oApp

   // HB_LangSelect("IT")
   * HB_SetCodePage("ITWIN")

   SetHandleCount( 100 )

   SET DATE FORMAT "dd-mm-yyyy"
   SET DELETED     ON
   SET CENTURY     ON
   SET EPOCH TO    year( date() ) - 20
   SET MULTIPLE    OFF


    Update()

   return nil

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

function Update()

   local cText, aData,  aNew, dMaxDate, oLotto
   local aFields :=   { { "DATA" , "D", 8, 0 },;
                        { "RUOTA", "C", 2, 0 },;
                        { "N1"   , "N", 2, 0 },;
                        { "N2"   , "N", 2, 0 },;
                        { "N3"   , "N", 2, 0 },;
                        { "N4"   , "N", 2, 0 },;
                        { "N5"   , "N", 2, 0 }}

   cText    := HB_MEMOREAD( "storico.txt" )
   cText    := FW_ALLTRIM( cText )
   cText    := StrTran( cText, CRLF, Chr( 10 ) )

   aData    := HB_ATokens( cText, Chr( 10 ) )


   AEval( aData, { |c,i| aData[ i ] := HB_ATokens( c, Chr( 9 ) ) } )
   AEval( aData, { |a,i| a[ 1 ] := uCharToVal( a[ 1 ], "D" ) } )

   XBROWSER aData

    oLotto:= TDatabase():Open( , "LOTTO", "DBFCDX", .T. )
    oLotto:Gobottom()
    dMaxDate := oLotto:Data
    ?dMaxDate //TAKE LAST RECORD DATE

    //CREATE TEMP
   DBCREATE( "TEMP.DBF", aFields, "DBFCDX", .T., "Storico" )


   aNew     := {}
   AEval( aData, { |a| If( a[ 1 ] > dMaxDate, AAdd( aNew, a ), ) } )
   FW_ArrayToDbf( anew )


   GO TOP
   XBROWSER ALIAS() SHOW RECID
   CLOSE DATA

return nil
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion