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

Loop in a Loop not working

Status
Not open for further replies.

Ed Andres

IS-IT--Management
Mar 27, 2001
142
US
I have the following code that I am trying to use to print part labels based on the quantity in the qty field. The code only does the first matching record and then stops. If I remove the FOR..ENDFOR loop the code will cycle through all matching records. I tried using LOOP with no luck. What am I missing?


SCAN ALL FOR TempData.print = .T. .AND. TempData.printed = .F.
Replace TempData.printed WITH .T.
nQty = TempData.qty
cPartno = TempData.partno
cDesc = TempData.desc
FOR x = 1 TO nQty
REPORT FORM \sched\reports\part_label2.frx NOCONSOLE TO PRINTER
ENDFOR
ENDSCAN

Thanks in advance for your help,
Ed
 
REPORT FORM will try to output all records that match your criteria, and eventually end up at end of file. Since the record pointer is now at EOF(), the SCAN will exit.
You probably need to add NEXT 1 to your REPORT FORM statement:

REPORT FORM \sched\reports\part_label2.frx NEXT 1 NOCONSOLE TO PRINTER


Dave S.
[cheers]
 
Looks like the report form is going through the entire table, then the next loop back to SCAN finds that you're already at EOF(), the end of the table, so it stops. Try adding the line "nCurRec=RECNO()" before the REPORT FORM and after it add the line "GO nCurRec". That should fix it. (You may want to make the placeholder variable "nCurRec" a local or private variable so it can't alter any identically-named variable in your code elsewhere.)
 
Dave,
The NEXT 1 did the trick!

Thanks to you and dbMark for the extra speedy reply (10 minutes tops!). There is not another support forum on the web better than this one and the folks who participate in it.

Thanks Again,
Ed
 
Just as another comment ...

Your FOR LOOP is going to cause the REPORT statement to be executed nQTY times. This is a very inefficient and awkward way to do this. If you had 300 labels to print you would be executing the report 300 times to get the 300 labels.

Usually you would like to execute the report once and have it working on a file of 300 records to produce the 300 labels.

In order to accomplish that, you should create a temporary file (cursor) and put 300 records into it. It does not even matter what you put in each record as long as your report form uses the variables you have created to print the labels. The temporary file is then being used as nothing more than a counting device.

Well, I am rambling on but if you understand what I am saying, it might be a better way to approach this.

I have some code below if you are interested in this alternative. It might not be perfect but gives you the general idea.


select 0
create table rptdata (dummy c(1))

select tempdata
go top
do while not eof()
if print = .T.
nQty = TempData.qty
cPartno = TempData.partno
cDesc = TempData.desc

select rptdata
zap
for j = 1 to nQty
append blank
endfor
go top

REPORT FORM \sched\reports\part_label2.frx NOCONSOLE
endif
select tempdata
skip
enddo




Don
dond@csrinc.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top