Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i Copy record of the same file (duplicate record) 1

Status
Not open for further replies.

virtualhawk

Programmer
Jan 14, 2003
3
US
How can i Copy record of the same file (duplicate record)
 
My redneck way of doing this. I am sure there is another way of doing it.

aStuff := Array(YourDB->(FCount()))

For nX := 1 To FCount()
aStuff[1][nX] := YourDB->(&(FieldName(nX)))
Next nX

YourDB->(DBAppend())

For nX := 1 To FCount()
YourDB->(&(FieldName(nX))) := aStuff[1][nX]
Next nX
Richard L. Hankins Jr.
Senior Programmer
Auction Services, Inc.
 
And a faster way of doing that would be to use FieldGet/FieldPut functions instead of macro expansion.

HTH
TonHu
 
Try This:
// Inside the record wanted
Copy Next 1 To Temp
Append From Temp
// Done
Juan Lucio Garcia
 
jlucio: Yuck! [sadeyes]
(Sorry, can't help myself)
This is probably the last way I'd do a record copy, ever, anywhere.

HTH
TonHu
 
TonHu,
It's a 2 liner and it works and it's the only way to do it in DBU. Having said that I sort of agree, think of all those wasted milliseconds of disk access?

Here's a version of Richard's copy above, self contained and avoiding macros.

function CloneRec(cDatabase)
local nLength := (cDatabase)->(fcount())
local aData := array(nLen) , x

for x := 1 to nLength
aData[x] := (cDatabase)->(fieldget(x))
next

// Add a record your way
(cDatabase)->(addrec())

for x := 1 to nLength
(cDatabase)->(fieldput(x,aData))
next
Ian Boys
DTE Systems Ltd
 
And then it should have been a threeliner, removing the temp database... ;-)
I can only agree on the DBU issue, but I have always avoided using DBU.

Your code is nice and clean, I could have written it myself, as I used to use the same style for Clipper code.

Thanks,
but, as I said, I couldn't help myself when I reacted as I did. s-)
 
hi

// sewt pointer to the desired records by seek command
stor all fields in memo variables
append blank
repl all fields with memo variables.

i think it solve your problem


alok
 
Alok,
Come on, at least use an array. I'd get bored after declaring the first 20 variables local! Ian Boys
DTE Systems Ltd
 
Yeah, I thought mine was alright... pretty dynamic and all. Richard L. Hankins Jr.
Senior Programmer
Auction Services, Inc.
 
Richard,

Not bad, but you used macros when you didn't have to so you get marked down.

I had a similar thing on a news group where someone suggested not putting a fcount() in a for/next loop but storing it to a variable first. I looked at the difference over 1 million loops and it was 65 seconds against 68. The thing is you only do it a couple of times normally so it makes little difference in paractice. Ian Boys
DTE Systems Ltd
 
// Gather
aTemp := ARRAY(FCOUNT())
AEVAL(aTemp, {|xExpression, nField| aTemp[nField] := FIELDGET(nField)})

// Scatter
AEVAL(aTemp, {|xExpression, nField| FIELDPUT(nField, xExpression)})
 
In reading my initial response, I assumed you'd be aliasing and appending a new record.. so to be totally correct, your code would look like this:

// Gather ( copy record )
aTemp := ARRAY(YourDBF->( FCOUNT() ) )
AEVAL(aTemp, {|xExpression, nField| aTemp[nField] := YourDBF->( FIELDGET(nField) )})

// Append your new blank record
YourDBF->( Dbappend() )

// Scatter ( populate it )
AEVAL(aTemp, {|xExpression, nField| YourDBF->( FIELDPUT(nField, xExpression))})
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top