How write a right name of a field

Post Reply
User avatar
Silvio.Falconi
Posts: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

How write a right name of a field

Post by Silvio.Falconi »

For a sample

the field is oDbf:CA1

If I have cField:="Ca1" // but I not Know the name of the field I made a function to create name of field
with
cRuota:= NomeRuota(nRuota)
cField:= Left(cRuota,2)+ltrim(str(nPosizione))


How I can make to found the field on oDbf (tadatabase)

I try with oDbf:&cField but not run ok

I tried also with fieldWBlock(cField,oDbf:nArea )
It return me an array

Image

I try also with
atemp:= fieldWBlock(cField,oDbf:nArea )
nNumero := atemp[1][1] but not is correct

How I can take it ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
Posts: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: How write a right name of a field

Post by Silvio.Falconi »

Perhaps I found a solution

nNumero := eval(oDbf:fieldWBlock(cField ))
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: How write a right name of a field

Post by nageswaragunupudi »

Simple:

Code: Select all | Expand

oDbf:FieldGet( cField )
oDbf:FieldPut( cField, <newvalue> )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
Silvio.Falconi
Posts: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: How write a right name of a field

Post by Silvio.Falconi »

nageswaragunupudi wrote:Simple:

Code: Select all | Expand

oDbf:FieldGet( cField )
oDbf:FieldPut( cField, <newvalue> )
 

I must only read it
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: How write a right name of a field

Post by nageswaragunupudi »

I must only read it


What do you mean? Did I not tell you oDbf:FieldGet( cField )? Is it not reading?

Next, oDbf:&cField also works.

Code: Select all | Expand

  local cField   := "NAME"

   oDbf  := TDataBase():Open( nil, "STATES.DBF", "DBFCDX", .T. )
   ? oDbf:FieldGet( cField ), oDbf:&cField
 


It works
Regards

G. N. Rao.
Hyderabad, India
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: How write a right name of a field

Post by James Bott »

How to write a right name of a field


Since you are already using a database object, instead of this:

oDbf:FieldGet( cField )
oDbf:FieldPut( cField, <newvalue> )

You can just do:

oDBF:ID
oDBF:Name

Where ID and NAME are fieldnames. Then you can do:

msgInfo( oDBF:ID )

To put data into a field of a database object you just do:

oDBF:ID := cID
oDBF:Name := cName

However you should always use a meaningful name for the database object, so it should be something like:

oCustomer:ID
oCustomer:Name

You should not use oDBF as an object name because all that tells you is that it is a database object, but not which database object. And, obviously you can't have multiple database objects open in the same routine all with the same name, like "oDBF." But you can have something like oCustomer and oInvoice open in the same routine since there is no name conflict.

Using these conventions makes your code very easy to read and understand, even years after you wrote it.
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
Silvio.Falconi
Posts: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: How write a right name of a field

Post by Silvio.Falconi »

James Bott wrote:
How to write a right name of a field


Since you are already using a database object, instead of this:

oDbf:FieldGet( cField )
oDbf:FieldPut( cField, <newvalue> )

You can just do:

oDBF:ID
oDBF:Name

Where ID and NAME are fieldnames. Then you can do:

msgInfo( oDBF:ID )

To put data into a field of a database object you just do:

oDBF:ID := cID
oDBF:Name := cName

However you should always use a meaningful name for the database object, so it should be something like:

oCustomer:ID
oCustomer:Name

You should not use oDBF as an object name because all that tells you is that it is a database object, but not which database object. And, obviously you can't have multiple database objects open in the same routine all with the same name, like "oDBF." But you can have something like oCustomer and oInvoice open in the same routine since there is no name conflict.

Using these conventions makes your code very easy to read and understand, even years after you wrote it.


James,
I have 57 fields
I not know wich field the function need, I not have the name of field

If I made a function Estrazione (n,r,p)
it must found the n record r route p position.
odbf:goto(n) // record

croute :=giveroute(r)
nposition:=p
cfield:= left(croute,2)+ltrim(str(nposition)) // sample NZ3
so
odbf:&cfield
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
Post Reply