Need some programing help.

Need some programing help.

Postby hag » Fri Jan 07, 2011 7:34 pm

I have a data base with 150 fields. 600 records indexed by account number.
While in a do while loop I need to grab the value of the 150 fields then select
the same record in another data base and populate the record with the
150 values from the first data base.

I can do it with a bunch of code but not efficently.

All help appreciated.
Thank you
Harvey
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California

Re: Need some programing help.

Postby ukoenig » Fri Jan 07, 2011 8:29 pm

Hello Harvey,

I don't know, database 1 the same structure like database 2 ???
( You can replace fields with equal fieldnames )

You can create a function like :

Code: Select all  Expand view

FUNCTION Rec_Copy ()
LOCAL FX, VALUES := {}

// read a record from Database 1
// -----------------------------------
DBSELECTAREA(1)
FOR FX := 1 TO FCOUNT()      // Fields --> Arrray
     AADD(VALUES, FIELDGET(FX))
NEXT
...
...
// copy the array to Database 2

DBSELECTAREA(2)

// jump to a defined record, append new or seek a value from database 1
// RECORD-LOCK needed !!!
// write the fields like :
// ---------------------------
FOR FX := 1 TO FCOUNT()      // Array --> Fields
     FIELDPUT(FX, VALUES[FX])
NEXT
 
RETURN NIL
 

Maybe You still need more Infos : FIELDPOS() and FIELDNAME() ?

Sample 1
USE Customer NEW
? FIELDPOS( "Name" ) // Result : 1
? FIELDGET( FIELDPOS( "Name" ) // Result : "James"

Sample 2
USE Customer NEW
USE Invoices NEW
? Customer ->( FIELDPOS( "Name" ) ) // Result : 1
? Customer ->( FIELDGET( FIELDPOS( "Name" ) ) ) // Result : "James"

Sample 3
USE Sales
? Sales->( FIELDNAME( 1 ) ) // Result : Branch

Sample 4
USE Customer NEW
? FIELDGET( 1 ) // Result : "James" ( of selected record-position, Field No. 1 = Name )

Sample 5
USE Customer NEW
? FIELDPUT( 1, "James" ) // Result : Field No. 1 = Name of selected record-position is replaced with "James"

I hope it helps
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Need some programing help.

Postby hag » Fri Jan 07, 2011 10:30 pm

Thanks Uwe. I'll try it very soon.
Thank you
Harvey
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California

Re: Need some programing help.

Postby hag » Sat Jan 08, 2011 1:24 am

works fine but needed one line of code.
I'm in a do while loop and at the top of the loop it needs

values := {}

Then it worked great.
Thank you
Harvey
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California

Re: Need some programing help.

Postby ukoenig » Sat Jan 08, 2011 1:34 am

Harvey,

I'm glad to hear, that it works for You.
This weekend, I will create a complete sample, how to use the different FIELD - functions.
There will be a Solution as well, updating a Record in Database 2 from Database 1( can be many fields ),
even the Structure is different.
( some Fields with the same Field-name from Database 1, but on different Positions ).

Best Regards
Uwe :lol:
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

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