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

Variable is not found

Status
Not open for further replies.

sdpsc

Technical User
Feb 10, 2001
76
I'm trying to create a program that will help us with formatting phone lists. It searches to see if the lname1 field exists, and if not, finds fields that may be the last name field and renames them. I'll run this when there is no lname1 field but there is one of the others, it always gives me a "Variable LN is not found" error. However, the column will still get renamed to lname1. Any help would be greatly appreciated! Thanks!


set stat on

x = 0
numFields=aFields(aColumns)


For i=1 To numFields
If Upper(aColumns(i,1))='LNAME1'
x = 1
EndIf
Next

if x = 0
For i=1 To numFields
If Upper(aColumns(i,1))='LASTNAME'
alter table testdb rename column lastname to LNAME1
EndIf
If Upper(aColumns(i,1))='LN'
alter table testdb rename column ln to LNAME1
EndIf
If Upper(aColumns(i,1))='LAST_NAME'
alter table testdb rename column last_name to LNAME1
EndIf
Next
endif
 
Change = for == in this part of the code:

If Upper(aColumns(i,1))=='LASTNAME'
alter table testdb rename column lastname to LNAME1
EndIf
If Upper(aColumns(i,1))=='LN'
alter table testdb rename column ln to LNAME1
EndIf
If Upper(aColumns(i,1))=='LAST_NAME'
alter table testdb rename column last_name to LNAME1
EndIf

Regards,

German
 
Ah, I hadn't quite realized FoxPro's syntax had the 2 ='s. Thanks!
 
For what it's worth, I've found it easier to use the FSIZE() function to determine whether a field exists rather than looping thru all the fields.

IF FSIZE('LNAME1') = 0 && doesn't exist
.
.
.
ENDIF


Jim
 
That would be nice Jim, but do you know why the below code doesn't work? I have a unique_id field, which I renamed to unique_id2 so unique_id wouldn't exist. It doesn't say that it doesn't exist though. Thanks!

IF fsize('UNIQUE_ID') == 0
set stat on
? 'There is no Unique_ID field.'
set stat off
EndIf
 
Doh, I shouldn't set the status off like that. Sigh.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top