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!

Identifying field type

Status
Not open for further replies.

astech

Programmer
Jul 25, 2000
59
ID
I have a table with fields like :

TableA
Field1 C 10
Field2 N 7,2
Field3 D 8

How do i identify all field types and widths and decimals with a programaticly.

thanks for all advices.
 
you can use COPY STRUCTURE EXTENDED to create a new table containing field's name, type, length, decimal places (if any. refer to it's help documentation for further details.

kilroy [trooper]
philippines
"and that's what we call creativity..."
 
Use afields() for a rogramatic solution:

FOR i = 1 TO AFIELDS(laTemp)
?"Field Name: "+laTemp(i,1)
?"Field Type: "+laTemp(i,2)
?"Field Width: "+TRANSFORM(laTemp(i,3))
?"Field Decimals: "+TRANSFORM(laTemp(i,4))
ENDFOR
 
Thanks for your advices.

But can i know it without an array,
i just wanna take a part of field.

like checking only :
Field2 N 7,2

 
You could use FIELD() to get the name, TYPE() to get the type, and FSIZE() to get the total width, but if it's numeric you wouldn't get the number of decimals.
Code:
lcName = Field(1)
lcType = Type(lcName)
lnWidth = FSize(lcName)
?lcName
?lcType
?lnWidth
Rick
 
The number of decimals in a numeric field is one of the few things you can't get directly. I guess it's a "missing" function that would be nice to have but apparently not too urgent since we already have COPY STRUCTURE EXTENDED or AFIELDS() to get what we need.

<HINT>An idea for the Visual FoxPro dream team!</HINT>
 
dbMark,
Any positive suggestions for the FoxPro team can be placed on the FoxWish list ( - click on 'Wish List' link on the left) - many of the improvements in VFP 6/7/8 and the upcoming Europa have started on this "list".

Rick
 
Rick, thanks for the suggestion. I had opened an account in 2002 with UniversalThread but never done much there. I'll submit a wish.

Okay, here's my awkward and complicated sample code to get the decimals of a numeric field using AFIELDS() and ASCAN(), allowing for the differences between VFP6 and later versions:
Code:
myFieldName="num_field"
USE myTable
DIMENSION myArray[1]
=AFIELDS("myArray","myTable")
* NOTE: ASCAN() parm 1 expects actual array name
*       either with or without quotes
*       otherwise use eval("arrayNameHolder")
IF " 06." $ VERSION())
   * VFP 6
   lcExact=SET("EXACT")
   SET EXACT ON
   ASCAN(myArray,UPPER(myField))
 * lnDecimals = myArray[INT(ASCAN(myArray,UPPER(myFieldName))/ALEN("myArray",2))+1,4]
   lnDecimals = myArray[ASUBSCRIPT("myArray",ASCAN(myArray,UPPER(myFieldName)),1),4]
   SET EXACT &lcExact
ELSE
   * VFP 7+
   lnDecimals = myArray[ASCAN(myArray,myvar,1,-1,4,15),4]
ENDIF
? lnDecimals
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top