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!

Inserting breaks every 200 records

Status
Not open for further replies.

edrossi

Programmer
Jan 24, 2002
42
US
I am trying to insert breaks into a table after every 200 records. So the breaks (#########) should like like the following:

123 Main St Richmond VA 22201
###################
125 Main St Richmond VA 22203

Is there any easy way to accomplish this task?

ER
 
Edrossi,
In a report, or in a table? Best Regards,
Scott

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Edrossi,
Okay, I'll assume you have a table called Address

USE ADDRESS IN 0
COPY STRU TO ADDBREAKS WITH PRODUCTION && retains indexes
USE ADDBREAKS IN 0
SELECT ADDRESS
GO TOP
lnCount = 1
DO WHILE NOT EOF()
SELECT ADDRESS
SCATTER MEMVAR MEMO &&Only need memo clause if you have memo fields
SELECT ADDBREAKS
APPEND BLANK
GATHER MEMVAR
IF lnCount = 200
SELECT ADDBREAKS
APPEND BLANK
REPLACE <fields> WITH '#########'
* Name all fields one, by one with the appropriate name, and assign the number of '#' characters to the field
lnCount = 0
ENDIF
lnCount = lnCount + 1
SELECT ADDRESS
SKIP
ENDDO

Copy this code, alter the table name as needed, and fix the fields, and run it. The good news is this is entierly non-distructive, so if it doesn't work the first time, just ZAP the ADDBREAKS table, and fix the code, run it again. Once you've got it all correct, just rename the table from ADDBREAKS to ADDRESS, and you're good to go. Best Regards,
Scott

&quot;Everything should be made as simple as possible, and no simpler.&quot;[hammer]
 
USE TblAddress

SCAN
IF MOD(RECNO(),200)=0
INSERT blank after
REPLACE Address with &quot;#########&quot;
ENDIF
endscan
 
I added code to automatically turn all character fields into &quot;#&quot;... You just need to update 'VarTargetTable'.

Brian


*****************************************************
VarTargetTable=&quot;ADDRESS.DBF&quot;

SET TALK OFF
USE &vartable
SCAN
IF MOD(RECNO(),200)=0
INSERT blank after
FOR x= 1 to AFIELDS(temparray,vartable)
IF temparray(x,2)=&quot;C&quot;
REPLACE (temparray(x,1)) with replicate(&quot;#&quot;,temparray(x,3))
endif
endfor
ENDIF
ENDSCAN
SET TALK ON
 
ER,
The biggest problem I see with the above soluitons is that that they only apply to one ordering of the data. If you use any index or sort ordering, and you'll lose this every 20 break.

Rick
 
INSERT BLANK...

Doesn't this append a record to the END of the table?
Isn't this the same as APPEND BLANK nowdays?
I'm certain the 'after' clause is ignored.

The maniac has the way to do it.

HTH
Regards

Griff
Keep [Smile]ing
 
No... I use both &quot;insert blank after&quot; and &quot;insert blank before&quot; (current record) with perfect results in VFP 5, 6 and 7.

&quot;append blank&quot; puts a new record at the end of a table.

Brian
 
I must have a mildly different version of VFP to you Brian,
ALL the above commands just do an 'Append blank' - perhaps your index is maintaining the order for you?

Try a native table (no index order set) and run the commands manually for yourself.

Regards

Griff
Keep [Smile]ing
 
Is your pointer at eof()? Try:

go 2
insert blank after
 
No, it doesn't matter where the cursor is, INSERT is included for backwards compatibility only and does an
APPEND - so that with really large tables VFP doesn't have to reshuffle huge numbers of records physically in a table.

Regards

Griff
Keep [Smile]ing
 
It's strange it doesn't work for you... I find it a useful command for manipulating a temp table that tracks user changes made in a grid on a form.
 
Sir,

I'm doing you an injustice. On a FREE table it works just as you say!

On a table with a link to a database it does not!

Please accept my apologies.

Regards

Griff
Keep [Smile]ing
 
If we grant that my solution does work, then there is another difference between the two solutions.

My program included the added row &quot;#####&quot; as a counter record, thus making rows 201, 401, 601 etc. as a &quot;###&quot; row; while Scott's solution does not, thus making rows 201, 402, 603 as a &quot;###&quot; row.

Brian
 
I almost *always* work on free tables :)

It's good to know that that logic won't work in a database... and that I shouldn't count on it's continued existence in VFP 8.

Brian
 
On a free table, in the beta version it works as you say.


Regards

Griff
Keep [Smile]ing
 
My question is - why do you want to insert this into your data?

Darrell 'We all must do the hard bits so when we get bit we know where to bite' :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top