FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Copy or paste one record
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Copy or paste one record
Posted: Fri Dec 05, 2014 12:53 PM

Hello,

Is there a method to copy or/and paste a complete record of a DBF, without knowing its structure?

Thanks a lot in advance for any help.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: Copy or paste one record
Posted: Fri Dec 05, 2014 01:48 PM
Hello, see this aid program.

Is in Portuguese, but is not difficult.

http://www.pctoledo.com.br/forum/viewtopic.php?f=1&t=12062

Download:

http://www.pctoledo.com.br/forum/filebase.php?c=0&f=141&page=1

Regards.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 159
Joined: Wed Mar 28, 2007 01:19 PM
Re: Copy or paste one record
Posted: Fri Dec 05, 2014 04:07 PM

Hello Michel.
To 'copy' and ´paste' database records I use the array-field functions SCATTER & GATHER with option for field checking.
I you want, I can post them here.
HTH & regards, Euclides

Posts: 300
Joined: Wed Jul 11, 2007 11:06 AM
Re: Copy or paste one record
Posted: Fri Dec 05, 2014 04:12 PM

Here is my code :

vdata:={}
for a=1 to fcount()
aadd(vdata,fieldget(a))
next
append blank

if rlock()
for e=1 to fcount()
fieldput(e,vdata[e])
next
unlock
skip 0
else
MsgAlert("Lock error !!")
endif

Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: Copy or paste one record
Posted: Fri Dec 05, 2014 05:24 PM

Hi. I do Exactly as Jack do it. The Source and Target dbfs must be identical.
Regards.

Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: Copy or paste one record
Posted: Fri Dec 05, 2014 11:09 PM
These functions work even if the database is not the same. Of coarse the field will not be copied if it does not exist in the other database but no error will occur.
You can also pass a record number so that you can take 1 record and update another record in the same database.
aData := scatter()
// Select other database
// Append blank or lock record
gather( aData )

Code (fw): Select all Collapse
function scatter( nRecNo )
   local nFldCount := fcount()
   local nCounter
   local aReturn
   local aValues := array( nFldCount )
   local aNames := array( nFldCount )
   if nRecNo == nil
      nRecNo := recno()
   endif

   goto nRecNo
   for nCounter = 1 to nFldCount
      aValues[ nCounter ] := fieldget( nCounter )
      aNames[ nCounter ] := fieldname( nCounter )
   next
Return( {aValues, aNames } )

function gather( aRecValues, nRecNo )
   local nFldCount := len( aRecValues[1] )
   local nCounter
   if nRecNo == nil
      nRecNo := recno()
   endif
   goto nRecNo
   for nCounter = 1 to nFldCount
      nFieldPos := fieldpos(aRecValues[ 2 ][ nCounter ])
      if nFieldPos > 0
         fieldput( nFieldPos, aRecValues[ 1 ][ nCounter ] )
      endif
   next
Return( Nil )
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Copy or paste one record
Posted: Sat Dec 06, 2014 08:20 PM

Thanks a lot for all your help, guys.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Copy or paste one record
Posted: Sun Jan 04, 2015 08:32 PM
An easy way:

Assume we want to copy Record at No 100 and paste over Record No. 200
Code (fw): Select all Collapse
USE CUSTOMER
DATABASE oDbf

oDbf:GoTo( 100 )
CUSTOMER->( DBGOTO( 200 ) )
oDbf:Save()


Assume we want to copy Record No: 150 and append the same data as a new record.
Code (fw): Select all Collapse
USE CUSTOMER
DATABASE oDbf

oDbf:GoTo( 150 )
CUSTOMER->( DBAPPEND() )
oDbf:Save()
Regards



G. N. Rao.

Hyderabad, India
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: Copy or paste one record
Posted: Mon Jan 05, 2015 01:27 PM

Dear Mr. Rao,

thank you for this example.
Would you be so kind to explain what exactly this lines are doing:

DATABASE oDbf

CUSTOMER->( DBGOTO( 200 ) )
Why don’t we use here
oDbf:DBGoto(200)

oDbf:Save()

Thanks in advance
Otto

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Copy or paste one record
Posted: Mon Jan 05, 2015 05:24 PM

CUSTOMER->( DBGOTO( 200 ) )

This is to prevent the buffer from being reloaded.

Another way you could do it:

oDBF:lBuffer:=.f.
oDBF:goto(200)
oDBF:save()

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Copy or paste one record
Posted: Thu Jan 08, 2015 01:58 PM
Maybe do You want to < RESET or REPLACE > defined vars of the new record ?

A test, using different copy-options for the destination record of types < numeric, logic and date > :
I added a new logic-field in DBF customer, to show how to receive different results.

Added many new options :

1. new copy-field-replacement
2. fieldprotection to replace fields with a new value
3. incremental seek
4. filter 2 - 6 can be a multiple selection fieldtyle N, L and D

The 2. record-copy shows the result of a protected field ( salary 11 ).
All other fields are replaced.

A 0 of the destination get APPENDS arecord
A >0 defines the destination record and replaces the values.



best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Copy or paste one record
Posted: Sat Jan 10, 2015 01:04 PM
For the final solution of the COPY-test, I added many options
In case something is still not working or possible to make it better, just give me a answer

Download :
http://www.pflegeplus.com/DOWNLOADS/Reccopy1.zip

Usage :

1. select any field-options for the record-copy
--- ( nothing selected will make a NORMAL copy without replacing something )
2. You can change from index to natural order
3. click on a record, to copy
---The record-number will be displayed in the start-get
4. use checkboxes to enable multiple filters
5. added incremental seek
6. possible to delete double names ( records ) after tests
7. possible to define multiple copys
8. exclude fields from replacing values with defined field-numbers
9. Fieldnumbers added to the xbrowse-header
10. Added a INI, to start with the last selected record
11. You can change the Dlg-background using the included function :
--- color = WD_BACKGRD( oDlg2, 1)
--- gradient = WD_BACKGRD( oDlg2, 2, nDColorF, nDColorB, nDGradPos, lDDirect)
--- brush = WD_BACKGRD( oDlg2, 3, , , , , cDBrush )
12. added a new field < Freelancer > to customer.dbf to handle the filter of logical fields

Destination-get = 0 will append a new record.
Destination-get > 0 will replace a record.

A selected replace-checkbox will auto-switch from .T. to .F. if nesessary,
to avoid double selections.
sample :
date-vars selected : < empty date >
date vars changed to DATE() will reset the checkbox < empty date > selected before to .F.


sample :
2 copies defined and replaced with empty date-fields ( 502, 503 )
2 rows before, 2 normal copys ( 500, 501 )




best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Copy or paste one record
Posted: Fri Jan 16, 2015 02:57 AM
I forgot another simpler way:

Code (fw): Select all Collapse
DBGOTO( 100 )
h := FW_RecToHash()
DBGOTO( 200)
FW_HashToRec( h )

The function takes care of locking and unlocking automatically.

We can also copy selected fields
Code (fw): Select all Collapse
DBGOTO( 100 )
h := FW_RecToHash( "FIRST,CITY,SALARY" )
DBGOTO( 200 )
FW_HashToRec( h )
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion