Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Check for field name in table
Message
From
20/01/2011 14:12:11
 
 
To
20/01/2011 10:17:41
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01496634
Message ID:
01496720
Views:
79
mmm - just for point of information - the solution i posted which i think is Tore's suggestion alerts me that the table does not contain a field called THH05 without an error message - i tried both yours and sergey's solution and got error messages when THH05 was not found - i will give you the full program which works and perhaps fill me in on the why your solution cannot be adapted:
cfile = 'c:\db\prg\menu\past.DBF'
use past
if 'thh05'$cfile = .F.
wait window "already changed"+CHR(13)+"Click to close" 
else
Alter Table c:\db\prg\menu\past.DBF Rename Column thh05 To thh11	
wait window "Past database file has been changed " 	
close all
endif
the following version produced error when rename command is encountered - ie it does not find the missing thh05 as field name as well sergey's.
close all
cfile='c:\db\prg\menu\past.DBF'
SELECT 0
USE (cFile) 
IF TYPE(ALIAS() + '.' + thh05) <> "U" 
  USE
  Alter Table c:\db\prg\menu\past.DBF Rename Column thh05 To thh11
else
wait window "File has already been altered"
ENDIF
USE
k



>Or, you could use FIELD()
>
>SELECT 0
>USE (cFile) 
>IF Empty(Field('thh05'))
>  USE
>  Alter Table c:\db\past.DBF Rename Column thh05 To thh11
>ENDIF
>USE
>
>
>
>
>>Not even close. You're checking for presence of string 'thh05' in the table name (including path). And comparing result of comparison with .F. is totally unnecessary. That what NOT is for
>>
>>SELECT 0
>>USE (cFile) 
>>IF TYPE(ALIAS() + '.' + thh05) <> "U" 
>>  USE
>>  Alter Table c:\db\past.DBF Rename Column thh05 To thh11
>>ENDIF
>>USE
>>
>>
>>
>>>sorry - i found solution in previous forum reply. I think Tore's help.
>>>
>>>cfile='c:\db\past.DBF' 
>>>if 'thh05'$cfile = .F.
>>>
>>>k
>>>etc
>>>>what code could i use to verify if a field name is present in a table.
>>>>
>>>>Alter Table c:\db\past.DBF Rename Column thh05 To thh11
>>>>
>>>>
>>>>this works fine however if the program is repeated thh05 is no longer present and an error message appears.
>>>>
>>>>i need an 'if' command to check for thh05
>>>>
>>>>thanks
>>>>k
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform