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

Replace not working in EXE but does in PRG

Status
Not open for further replies.

DaBuzz

Programmer
Nov 8, 2002
40
US
I have what should be a very simple problem.

I have a very simple form - local table for one user - that I have them enter data from.

This gets saved in table New_one. I then fill in some additional fields with values entered using the following in a Do while not EOF.

Replace Startdate with ASTRDATE

Basically populating 2 fields with 1 data entry before they are appended to another table.

If I run the program in the command window it works fine.
When I add it to the application none of the "REPLACE" statements work.
I have tried:
Replace New_one.Startdate with New_one.ASTRDATE
just to be more specific but even that doesn't work.

I use the file, select it, go to the top record then start my DO WHILE.
Again it works fine from the command window but not the executable.
I've run into this before and have solved it by scatter memvar and issuing m.field2=m.field1 then gather memvar - but figured I should learn why the replace command doesn't work.

Thanks.


 
I would try something like this
Code:
select new_one
set order to 0
go top
do while .not. eof()
  replace new_one.startdate with new_one.astrdate
  skip
enddo

You could also try:
Code:
select new_one
set order to 0
go top
replace all new_one.startdate with new_one.astrdate

Good luck

Regards

Griff
Keep [Smile]ing
 
DaBuzz,

There are two common situations where REPLACE appears not to work:

- You are trying to replace in a work area other than the current work area (in other words, you need to SELECT the correct alias before you replace).

- The table you are replacing into is empty, is at eof, or only contains deleted or out-filtered records.

I would suggest you check to see if either of those apply in this case.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
There is a third gotcha...

If your table is indexed on the field you are replacing, you may disturb the ORDER of the records processed in a 'do while/endo' or 'scan/endscan' loop - so the if your first replace puts your record at the END of the index order, the skip will result in an eof() situation... hence only one record will be processed (worst case).

Hence why my code had the 'set order to 0' statement prior to the 'go top'.

Good luck again

Regards

Griff
Keep [Smile]ing
 
If your table is indexed on the field you are replacing, you may disturb the ORDER of the records processed in a 'do while/endo' or 'scan/endscan' loop

Good point. This was the reason for the old NOFOLLOW clause in a Browse. Do we still have that, I wonder, or was it dBASE-specific?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
There is a reserved word NOFOLLOW in the VFP9 help, but no mention of it in the help for BROWSE, an undocumented feature?

Regards

Griff
Keep [Smile]ing
 
Looks like BROWSE does accept NOFOLLOW, but as far as I can see, it doesn't do anything.

So not really an undocumented feature, more a non-feature. But obviously it's needed for compatibility purposes.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks for the input.

Good news is I finally solved it.
I added Close data and use then select and the problem went away.

I had been issuing the select - and got no errors, but it seemed to still not be selecting the table.

When running from the command prompt I had to open the table then run the program.

This table didn't have any indexes so that wasn't the problem but that was good to know for the future.

I don't know why I was using the dowhile to walk through each record, I've used the "replace all new_one.startdate with new_one.astrdate" without the dowhile numerous times but with Griff pointing it out as something to try, it definitely applies for this - so why I wasn't doing it that way to begin with befuddles me.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top