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!

replace statement for a cursor

Status
Not open for further replies.

BlackDice

Programmer
Mar 1, 2004
257
0
0
US
I created a cursor with a field specified like this:

Code:
padr(' ',30,' ') as rideextras

a few lines down, I do a replace on that field with a string variable, but it doesn't update the field. I've tried using TableUpdate(), changing the buffering mode, setting multilocks on, and I just can't seem to update the field. The update statement looks like this:

Code:
replace crsrides.rideextras with lcExtras


any help is appreciated. Thanks in advance

BlackDice

 
Hi Black,

Please give the total coding for the cursor, or is it you havenot included the READWRITE clause?

Regards,

Koen
 
as I posted earlier, I got it now. I did have the 'READWRITE' in the statement, but I had this:

Code:
replace crsrides.rideextras with lcExtras

instead of this:

Code:
replace crsrides.rideextras with lcExtras in "crsrides"

BlackDice

 
This is probably why the REPLACE did not occur, from the VFP help file:
"Note If the IN clause is omitted, no replacement occurs if the record pointer is at the end of the file in the current work area and you specify a field in another work area."

-mike
 
BlackDice,

Have run into this a few times myself. It is as denware has pointed out. So, I pretty much use the "in" clause with all statements that allow it as an optional clause. I find that I don't have to worry about what work area is selected so much, the code is more readable, and in the end more maintainable. Now if I could just get a handle on actually putting comment lines in my code so that the coders that have to work on my stuff understand what I was doing and thinking... [bigsmile]

Well anyways, you figured it out. The only reason I really posted was to ask what the reason was behind padr(' ',30,' ') as rideextras, while it will work I think that perhaps space(30) as rideextras would have been more straight-forward.


boyd.gif

 
well, the reason I did the padr() was because I used a fieldname first, then decided not to, and just left the space there as I was testing it out. I did forget to change it to something better, but as you know, I'm still pretty new at Foxpro, so that's the excuse I'm using :). thanks, craigsboyd and denware!

BlackDice

 
One additional suggestion: Make it
Code:
replace rideextras with lcExtras in "crsrides"
As the in "crsrides" tells foxpro to replace the field rideextras in crsrides. Replace doesn't care about tablenames besides that given with "in" and a replace is always done in *one* table/view/cursor, and that belongs in the "in" clause.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top