Page 1 of 1

creation dbf with

Posted: Sat Oct 12, 2024 8:56 pm
by Silvio.Falconi
I wish create a dbf from array

oVirtuale:ArrayToDBF( atempDbf, , nil, .t., .t. )

but oVirtuale not have the same structure of atempDbf

oVitruale init with

Code: Select all | Expand

local aFields := { { "CONCORSO", "C", 3, 0 },;
                   { "DATA", "D", 8, 0 },;
                   { "BA1", "N", 2, 0 },;
                   { "BA2", "N", 2, 0 },;
                   { "BA3", "N", 2, 0 },;
                   { "BA4", "N", 2, 0 },;

....
 


and atempDbf have

Code: Select all | Expand

local aFields := { { "NUMERO", "N", 6, 0 },;
                   { "DATA", "D", 8, 0 },;
                   { "CONCORSO", "C", 3, 0 },;
                   { "BA1", "N", 2, 0 },;
                   { "BA2", "N", 2, 0 },;
                   { "BA3", "N", 2, 0 },;
                   { "BA4", "N", 2, 0 },;

....
 
I used oVirtuale:ArrayToDBF( atempDbf, cItemFlds , nil, .t., .t. )

where cItemFlds is

Code: Select all | Expand

 static cItemFlds  :="CONCORSO,DATA,BA1,BA2,BA3,BA4,BA5,CA1,CA2,CA3,CA4,CA5,FI1,FI2,FI3,FI4,FI5,GE1,GE2,GE3,GE4,GE5,MI1,MI2,MI3,MI4,MI5,NA1,NA2,NA3,NA4,NA5,PA1,PA2,PA3,PA4,PA5,RM1,RM2,RM3,RM4,RM5,TO1,TO2,TO3,TO4,TO5,VE1,VE2,VE3,VE4,VE5,NZ1,NZ2,NZ3,NZ4,NZ5"
 
make me error on oVirtuale:ArrayToDBF( atempDbf, cItemFlds , nil, .t., .t. )

error

Code: Select all | Expand

 Error description: Error DBFCDX/1021  Errore nella dimensione dei dati: BA1
   Args:
     [   1] = N   100

Stack Calls
===========
   Called from: .\source\classes\database.prg => FIELDPUT( 0 )
   Called from: .\source\function\dbffunc2.prg => FW_ARRAYTODBF( 586 )
   Called from: .\source\classes\database.prg => TDATABASE:HB_EXECFROMARRAY( 0 )
   Called from: .\source\classes\database.prg => TDATABASE:ARRAYTODBF( 1637 )
   Called from: Source\test.prg => LOAD_DBF( 584 )
   Called from: Source\test.prg => ESTRAZIONE( 106 )
   Called from: Source\test.prg => MAIN( 40 )




oLotto:gobottom()

xbrowser olotto TITLE "OLOTTO" ----> I see all ok

atempDbf:= oLotto:DbfToArray()

xbrowser atempDbf TITLE "ATEMPDBF" ---> I see all ok

oVirtuale:=TDatabase():Open( , cDir+"Virtuale", "DBFCDX", .T. )
oVirtuale:SetOrder( 0 )
oVirtuale:ArrayToDBF( atempDbf, cItemFlds , nil, .t., .t. ) ----> make error
oVirtuale:close()


Any solution pls

Re: creation dbf with

Posted: Wed Oct 16, 2024 6:36 pm
by Rick Lipkin
Silvo

I use the array to create my database structure
xVol := "C"

Code: Select all | Expand

DO WHILE .T.
   SITEDBF := "TEMP"+(SUBSTR(TIME(),7,2)+SUBSTR(TIME(),4,2))+".DBF"
   IF .not. FILE( xVol+"\DBTMP\"+SITEDBF )
      EXIT
   ENDIF
ENDDO

cName := "Opening Temp Table "+xVol+"\DBTMP\"+SITEDBF
oSay1:ReFresh()
SysReFresh()

DBF_STRU := { }
AADD( DBF_STRU, { "CUSTOMERID",   "C",  10,  0 } )
AADD( DBF_STRU, { "CUSTNAME",     "C",  50,  0 } )
AADD( DBF_STRU, { "SCEISID",      "C",  20,  0 } )
AADD( DBF_STRU, { "Date",         "D",   8,  0 } )
AADD( DBF_STRU, { "InvoiceTp",    "C",  20,  0 } )
AADD( DBF_STRU, { "InvNo",        "C",  10,  0 } )
AADD( DBF_STRU, { "BILLED",       "N",  12,  2 } )
AADD( DBF_STRU, { "PAID",         "N",  12,  2 } )
AADD( DBF_STRU, { "ADJUST",       "N",  12,  2 } )
AADD( DBF_STRU, { "CURRENT",      "N",  12,  2 } )
AADD( DBF_STRU, { "OVER30",       "N",  12,  2 } )
AADD( DBF_STRU, { "OVER60",       "N",  12,  2 } )
AADD( DBF_STRU, { "OVER90",       "N",  12,  2 } )
AADD( DBF_STRU, { "FINANCE",      "N",  12,  2 } )
AADD( DBF_STRU, { "TOTAL",        "N",  12,  2 } )
AADD( DBF_STRU, { "CurrDay",      "D",   8,  0 } )
AADD( DBF_STRU, { "Days",         "N",  10,  0 } )

DBCREATE( xVol+"\DBTMP\"+SITEDBF, DBF_STRU )




Re: creation dbf with

Posted: Thu Oct 17, 2024 1:59 pm
by karinha
Good morning Rick. Sorry for my stupidity, but I can't understand your function. Could you please make a complete example? Something's wrong, it's not right... I think... hahahaha.

Buenos días rick. Perdón por mi estupidez, pero no puedo entender su función. ¿Podrías hacer un ejemplo completo? Algo anda mal, no está bien... creo... jajajaja.

Gracias, tks.

Regards, saludos.

Re: creation dbf with

Posted: Thu Oct 17, 2024 8:38 pm
by Rick Lipkin
Karinha

this creates a unique database name to be created below

Code: Select all | Expand

DO WHILE .T.
   SITEDBF := "TEMP"+(SUBSTR(TIME(),7,2)+SUBSTR(TIME(),4,2))+".DBF"
   IF .not. FILE( xVol+"\DBTMP\"+SITEDBF )
      EXIT
   ENDIF
ENDDO


DBF_STRU := { }  creates a blank array


these lines

create the array data structure

AADD( DBF_STRU, { "CUSTOMERID",   "C",  10,  0 } )
AADD( DBF_STRU, { "CUSTNAME",     "C",  50,  0 } )
AADD( DBF_STRU, { "SCEISID",      "C",  20,  0 } )
AADD( DBF_STRU, { "Date",         "D",   8,  0 } )
AADD( DBF_STRU, { "InvoiceTp",    "C",  20,  0 } )
AADD( DBF_STRU, { "InvNo",        "C",  10,  0 } )
AADD( DBF_STRU, { "BILLED",       "N",  12,  2 } )
AADD( DBF_STRU, { "PAID",         "N",  12,  2 } )
AADD( DBF_STRU, { "ADJUST",       "N",  12,  2 } )
AADD( DBF_STRU, { "CURRENT",      "N",  12,  2 } )
AADD( DBF_STRU, { "OVER30",       "N",  12,  2 } )
AADD( DBF_STRU, { "OVER60",       "N",  12,  2 } )
AADD( DBF_STRU, { "OVER90",       "N",  12,  2 } )
AADD( DBF_STRU, { "FINANCE",      "N",  12,  2 } )
AADD( DBF_STRU, { "TOTAL",        "N",  12,  2 } )
AADD( DBF_STRU, { "CurrDay",      "D",   8,  0 } )
AADD( DBF_STRU, { "Days",         "N",  10,  0 } )
this creates the temp database name generated above and
DBCREATE( xVol+"\DBTMP\"+SITEDBF, DBF_STRU ) // takes the array and creates the database


copy this code and you will see how the code works .. with a random name generated by the time() function and the array structure is created by another array DBF_STRU ..

Rick Lipkin

Re: creation dbf with

Posted: Sat Oct 19, 2024 1:48 pm
by karinha
Thanks Rick. Now I understand. I modified it a little, so beginners like me with little experience/intelligence can understand. I hope it doesn't bother you.

Gracias Rick. Ahora lo entiendo. Lo modifiqué un poco, para que los principiantes como yo con poca experiencia/inteligencia puedan entenderlo. Espero que no te moleste.

Code: Select all | Expand

// Original by Rick Lipkin:
// https://forums.fivetechsupport.com/viewtopic.php?f=3&t=45007&p=274888&sid=4fd10da1789049fb5a17e330f466a2c9#p274857

// C:\FWH\SAMPLES\RICKSTR.PRG
// MODIFIED by Kapiabafwh@gmail.com in: 19/10/2024 - João Santos. São Paulo - Brazil.

#include "FiveWin.ch"

FUNCTION Main()

   LOCAL xLocalDBF := "C:\TMP\" // .DBF Folder.
   LOCAL Dbf_Stru               // structure of .DBF.
   LOCAL cFileRick, cNameDBF    // NAME.DBF TEMPORARY

   HB_GCALL( .F. )

   WHILE( .T. )

      SYSREFRESH()

      cNameDBF := "TEMP" + ( SubStr( Time(), 7, 2 ) + ;
                             SubStr( Time(), 4, 2 ) ) + ".DBF"

      IF .NOT. FILE( xLocalDBF + cNameDBF )

         EXIT

      ENDIF

   ENDDO

   Dbf_Stru := {}  // creates a blank array

   // these lines
   // create the array data structure
   AADD( Dbf_Stru, { "CUSTOMERID",   "C",  10,  0 } )
   AADD( Dbf_Stru, { "CUSTNAME",     "C",  50,  0 } )
   AADD( Dbf_Stru, { "SCEISID",      "C",  20,  0 } )
   AADD( Dbf_Stru, { "Date",         "D",  08,  0 } )
   AADD( Dbf_Stru, { "InvoiceTp",    "C",  20,  0 } )
   AADD( Dbf_Stru, { "InvNo",        "C",  10,  0 } )
   AADD( Dbf_Stru, { "BILLED",       "N",  12,  2 } )
   AADD( Dbf_Stru, { "PAID",         "N",  12,  2 } )
   AADD( Dbf_Stru, { "ADJUST",       "N",  12,  2 } )
   AADD( Dbf_Stru, { "CURRENT",      "N",  12,  2 } )
   AADD( Dbf_Stru, { "OVER30",       "N",  12,  2 } )
   AADD( Dbf_Stru, { "OVER60",       "N",  12,  2 } )
   AADD( Dbf_Stru, { "OVER90",       "N",  12,  2 } )
   AADD( Dbf_Stru, { "FINANCE",      "N",  12,  2 } )
   AADD( Dbf_Stru, { "TOTAL",        "N",  12,  2 } )
   AADD( Dbf_Stru, { "CurrDay",      "D",  08,  0 } )
   AADD( Dbf_Stru, { "Days",         "N",  10,  0 } )

   DBCREATE( xLocalDBF + cNameDBF, Dbf_Stru )

   cFileRick := cNameDBF

   IF FILE( xLocalDBF + cFileRick )

      MsgInfo( "New .dbf file created successfully! -->" + cNameDBF, ;
               "New .dbf file created successfully! -->" + cNameDBF)

   ELSE

      MsgInfo( ".DBF file was not created. Fatal error!", ;
               ".DBF file was not created. Fatal error!" )

   ENDIF

   HB_GCALL( .T. )

RETURN NIL

// FIN / END - kapiabafwh@gmail.com
Gracias. tks.

Regards, saludos.

Re: creation dbf with

Posted: Sat Oct 19, 2024 2:17 pm
by nageswaragunupudi

Code: Select all | Expand

atempDbf := oLotto:DbfToArray( cItemFlds )
oVirtuale:ArrayToDBF( atempDbf, ... )
But, the best method is:

Code: Select all | Expand

USE VIRTUALE
APPEND FROM LOTTO