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

Edit selected results in a VFP DBF column

Status
Not open for further replies.

Flowerpwr

Technical User
Apr 24, 2011
2
US
I have VFP7 and have a key column with numeric values. I have edited the Keys themselves and now want to go to the DBF with existing values and edit existing results.

Ex,
Tkpr_key (column)
3
5
11

I want all the instances in that column of 5 and Replace them all with 45.

Using Tpkr_key excl
Replace all...

ect I have not been able to figure out what I am doing wrong.
 
Please forgive the stupid question..

Can anyone give me any advise?

I tried all sorts of close matches to :

Replace all Ey_key WHERE 5 WITH =45

results in brackets, not..

I have done this before but it was years ago and I am
a bit frazzled over it!

Any help would be Extremely appreciated!
Thank you, Barb
 
Replace all Tkpr_key with 45 for Tkpr_key=5

If I understood your question right.
 
Yes, that's the syntax.

Note that it may not work if you've SET ORDER TO an index on that column. Set any other index order (or none) to get it to work properly.
 
Yes Dan, one would expect that with an index on the tkpr_key-field the replaces could/would go wrong. After the first replace the indexpointer points to 45 thereby jumping over the remaining records 5 till 44.
I just did a little test in 9sp2 and found to my surprise that it didn't matter. Even with an index the replaces went right.
Can you confirm this?
 
Hi,

The index would matter if the command were

Replace all Tkpr_key with 45 WHILE Tkpr_key=5

The FOR clause does not care for indexes.

hth

Mark
 
The FOR clause does not care for indexes.

This is a fairly recent change in VFP, for what it's worth. That's why I said "may not work" instead of "will not work".

(That's if *any* change to VFP can truly be considered recent. :))

I don't remember offhand whether it was 7 or 8, but it was an intentional change. Older versions most definitely cared. (It used to be a specific warning in the help file.)
 
According to the Hackers Guide for VFP 6.0, the problem only applies if a WHILE clause is present, not a FOR clause.

In other words, REPLACE .... WHILE might not produce the desired result if the field you are replacing is part of the WHILE expression. But REPLACE ... FOR won't have that problem.

But, I wonder why we're having this discussion. It might be of passing interest to some of us, but the original questioner has got his answer. He never said anything about using a WHILE clause. Aren't we in danger of confusing him with this superfluous information?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Just for the sake of discussion: Version 3.0b went right BUT Foxbase 2.1 (dos) did go wrong after the first replace.
Case closed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top