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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is the field exist ? 3

Status
Not open for further replies.

FoxWing

Programmer
Dec 20, 2004
44
0
0
GB
Hi,

Can anyone tell me how to know whether a field in the table exist or not ?

Thanks

 
check out the function afields in the help
also if a field does not exist then type("table.fielname")=="U"

hth,

Stefan
 
Another way:

IF FSIZE('myfield') = 0
*** doesn't exist
ENDIF

Jim
 
FoxWing,

I wrote the following code for myself:
Code:
LPARAMETERS TableName, FieldName
LOCAL ARRAY AliasArray[1,1]
LOCAL ARRAY DbfArray[1,1]
LOCAL;
  PreviousSafety , ;
  RetVal , ;
  PreviousAlias , ;
  aPart , ;
  AliasName , ;
  FoundDbf , ;
  QQ___QQ [COLOR=green]&& a placeholder for declaring local variables[/color]

IF USED(TableName) [COLOR=green]&& ie TableName was a used ALIAS[/color]
  AliasName = TableName
ELSE [COLOR=green]&& parameter <TableName> wasn't an alias - so see if the table is already open under a different alias[/color]
  PreviousAlias = ALIAS() [COLOR=green]&& to return the user to the work area they were in before re-selecting[/color]
  AUSED(DbfArray) [COLOR=green]&& declared as a LOCAL array[/color]

  FOR EACH aPart IN DbfArray [COLOR=green]&& scan through the array of aliases[/color]
    IF VARTYPE(aPart)=[C] AND JUSTSTEM(DBF(aPart)) = UPPER(TableName) [COLOR=green]&& aPart will be the work area number every other pass[/color]
      AliasName = aPart
      FoundDbf = .T.
      EXIT
    ENDIF
  ENDFOR

  IF NOT FoundDbf [COLOR=green]&& the dbf was NOT already open, so open it in an empty work area. Don't need to be in the work area as AFIELDS accepts the alias as a parameter[/color]
    USE (TableName) IN 0 AGAIN ALIAS CheckForField
    AliasName = [CheckForField]
  ENDIF

  SELECT (IIF(NOT EMPTY(PreviousAlias) AND USED(PreviousAlias), PreviousAlias, 0))
ENDIF
AFIELDS(AliasArray, AliasName) [COLOR=green]&& declared as a LOCAL array[/color]
RetVal = 0<ASCAN(AliasArray,UPPER(FieldName))
USE IN (IIF(USED([CheckForField]),[CheckForField],0))
RETURN RetVal

Hope that helps,

Stewart
PS If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi!
Here i sa bit of code I used.

Code:
*FUNCTION modify_table_financieel
IF USED("financieel")
  SELECT financieel
  USE
ENDIF
  
use financieel excl
if type("financieel.ToezNul")="U"
  alter table Financieel add column ToezNul L
ENDIF
if type("financieel.ToezAlOntv")="U"
  alter table Financieel add column ToezAlOntv L
ENDIF
if type("financieel.Depot")="U"
  alter table Financieel add column Depot N(10,2)
ENDIF

USE
-Bart
 
Here is an example

USE Company IN 0
IF EMPTY(FIELD('CITY', 'Company'))
wait window 'The field does not exits'
ELSE
wait window 'Field exists'
ENDIF

** you can create a function like this
Function FieldExists(pcFieldName, pcTableName)
RETURN EMPTY(FIELD(UPPER(pcFieldName), pcTableName))
EndProc

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top