Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
APPEND BLANK in 'MyDBF' not consistent?
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00422792
Message ID:
00423232
Views:
17
>more like ..
>select FileToAppend && Its actually a blank cursor
>zap
>Select FileToRead
>gotop
>scan && !eof()
>Match=FileToRead.Field1
>Total=0
>scan while FileToRead.Field1=Match
>Total=Total+FileToRead.Field2
>appen blank in 'FileToAppend' && Works okay here
>repl FileToAppend.Field1 with FileToRead.Field1,FileToAppend.Field2 with FileToRead.Field2
>endscan &&while FileToRead.Field1=Match
>appen blank in 'FileToAppend' && Works okay here except for eof()
>repl FileToAppend.Field1 with "Total",FileToAppend.Field2 with Total && Adds a blank record but does not replace **UNLESS**
>endscan &&!eof()
>
>**UNLESS**
>I use the following syntax:
>Select FileToAppend
>append blank
>replace .....
>select FileToRead
>endscan &&!eof() , etc.

The reason is that VFP's REPLACE verb won't update the record in another work area if the work area you're in is positioned on the phantom record in the current work area; by changing which workarea you're on, you change to the work area that's -not- at EOF() and find that you can update...

I'd suggest changing to something like:
select FileToAppend && Its actually a blank cursor
zap
Select FileToRead
go top
DO WHILE ! EOF() && !eof()
  Match=FileToRead.Field1
  Total=0
  SCAN while FileToRead.Field1=Match
    Total=Total+FileToRead.Field2
    INSERT INTO FileToAppend VALUES (FileToRead.Field1, FileToRead.Field2)
  endscan &&while FileToRead.Field1=Match
  INSERT INTO FileToAppend VALUES ('Total',Total)
ENDDO
This also avoids a logic bug caused by using two SCANs; each ENDSCAN causes a SKIP, so the first record of each subsequent group is lost in your original code. You can also add an IN clause to your REPLACE that specifies which target workarea you intend to reference rather than use alias.fieldname:

REPLACE Field1 WITH 'Total', Field2 WITH Total IN FileToAppend
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform