How write a right name of a field

How write a right name of a field

Postby Silvio.Falconi » Thu Apr 28, 2022 11:13 am

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: 7033
Joined: Thu Oct 18, 2012 7:17 pm

Re: How write a right name of a field

Postby Silvio.Falconi » Thu Apr 28, 2022 11:41 am

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
Silvio.Falconi
 
Posts: 7033
Joined: Thu Oct 18, 2012 7:17 pm

Re: How write a right name of a field

Postby nageswaragunupudi » Thu Apr 28, 2022 2:54 pm

Simple:
Code: Select all  Expand view
oDbf:FieldGet( cField )
oDbf:FieldPut( cField, <newvalue> )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10619
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How write a right name of a field

Postby Silvio.Falconi » Thu Apr 28, 2022 3:00 pm

nageswaragunupudi wrote:Simple:
Code: Select all  Expand view
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
Silvio.Falconi
 
Posts: 7033
Joined: Thu Oct 18, 2012 7:17 pm

Re: How write a right name of a field

Postby nageswaragunupudi » Thu Apr 28, 2022 3:05 pm

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 view
  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
nageswaragunupudi
 
Posts: 10619
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How write a right name of a field

Postby James Bott » Thu Apr 28, 2022 6:19 pm

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
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: How write a right name of a field

Postby Silvio.Falconi » Fri Apr 29, 2022 8:08 am

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
User avatar
Silvio.Falconi
 
Posts: 7033
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

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