| Group | Item | Lot | Qty. | Samples | Failure | Pass/Fail |
| A | A-001 | #1 | 3,000 | 150 | 50 | Fail |
| A-001 | #2 | 2,000 | 200 | 5 | Pass | |
| A-001 | #3 | 1,000 | 100 | 10 | Pass | |
| A-002 | #1 | 1,500 | 200 | 21 | Fail | |
| A-002 | #2 | 2,500 | 250 | 10 | Pass | |
| Group A Total | 10,000 | 900 | 96 | |||
| B | B-001 | #1 | 500 | 80 | 5 | Pass |
| B-001 | #2 | 750 | 80 | 3 | Pass | |
| Group B Total | 1,250 | 160 | 8 | |||
| ...... | ......................... | ........ | ............... | ........ | ....... | ........ |
| Grand Total | xx,xxx | xx,xxx | xx,xxx |
| Group | Item | Lot | Qty. | Samples | Failure | Pass/Fail |
| A | A-001 | #1 | 3,000 | 150 | 50 | Fail |
| #2 | 2,000 | 200 | 5 | Pass | ||
| #3 | 1,000 | 100 | 10 | Pass | ||
| Item A-001 Total | 6,000 | 450 | 65 | |||
| A-002 | #1 | 1,500 | 200 | 21 | Fail | |
| #2 | 2,500 | 250 | 10 | Pass | ||
| Item A-002 Total | 4,000 | 450 | 31 | |||
| Group A Total | 10,000 | 900 | 96 | |||
| B | B-001 | #1 | 500 | 80 | 5 | Pass |
| #2 | 750 | 80 | 3 | Pass | ||
| Item B-001 Total | 1,250 | 160 | 8 | |||
| Group B Total | 1,250 | 160 | 8 | |||
| ....... | .............................. | ............ | ............. | .............. | ........... | |
| Grand Tota | xx,xxx | xx,xxx | xx,xxx |
| Group | Item | Lot | Qty | Samples | Failure |
| A | A-001 | #1 | 3000 | 150 | 50 |
| A | A-001 | #2 | 2000 | 200 | 5 |
| A | A-001 | #3 | 1000 | 100 | 10 |
| A | A-002 | #1 | 1500 | 200 | 21 |
| A | A-002 | #2 | 2500 | 250 | 10 |
| B | B-001 | #1 | 500 | 80 | 5 |
| B | B-001 | #2 | 750 | 80 | 3 |
Data requirement (ตัวแปรที่ต้องกำหนด)
จากตัวอย่างรายงาน Quality control report ข้างต้น จะเห็นได้ว่ามีการพิมพ์บรรทัดยอดรวมอยู่
2 บรรทัดด้วยกันคือ Group total และ Grand total ดังนั้นเราจึงต้องมีการกำหนดตัวแปรมาใช้ในการสะสมค่า
ดังนี้
| Group.qty | Grand.qty |
| Group.sample | Grand.sample |
| Group.failure | Grand.failure |
Data requirement (ตัวแปรที่ต้องกำหนด)
จากตัวอย่างรายงาน Quality control report ข้างต้น จะเห็นได้ว่ามีการพิมพ์บรรทัดยอดรวมอยู่
3 บรรทัดด้วยกันคือ Item total, Group totalและ Grand total โดยจะพิมพ์บรรทัด
Item total เมื่อมีการเปลี่ยนค่า Item และจะพิมพ์บรรทัด Group total เมื่อมีการเปลี่ยนค่า
Group
คำถาม: ถ้ามีการเปลี่ยนค่า Group แต่ Item ไม่เปลี่ยน จะพิมพ์บรรทัด
Total บรรทัดใด
เราจึงต้องมีการกำหนดตัวแปรมาใช้ในการสะสมค่า ดังนี้
| Item.qty | Group.qty | Grand.qty |
| Item.sample | Group.sample | Grand.sample |
| Item.failure | Group.failure | Grand.failure |
initialize:
cur.line = 1
GOSUB print.heading
grand.qty = 0: grand.samples = 0: grand.failure =
0
READ group$, Item$, Lot$, qty, samples, failure
RETURN
print.heading:
PRINT TAB(30); "Quality control report"
PRINT TAB(5); "Group"; TAB(15); "Item"; TAB(25); "Lot";
TAB(35); "Qty";
PRINT TAB(45); "Samples"; TAB(55); "Failure"; TAB(65);
"Pass/Fail"
RETURN
process:
DO UNTIL group$ = "eof"
group.qty = 0: group.samples = 0: group.failure
= 0
previous.group$ = group$
DO UNTIL (group$ <> previous.group$)
OR (group$ = "eof")
status$ = "Pass"
IF (failure / samples
* 100) > 10 THEN
status$
= "Fail"
END IF
IF cur.line > 20 THEN
PRINT
"Press any key to continue ..."
char$
= INPUT$(1)
CLS
GOSUB
print.heading
cur.line
= 1
END IF
cur.line = cur.line
+ 2
PRINT TAB(5); group$;
TAB(15); Item$; TAB(25); Lot$;
PRINT TAB(35); USING
"##,### ##,### ##,###"; qty; samples;
failure;
PRINT TAB(65); status$
group.qty = group.qty
+ qty
group.samples = group.samples
+ samples
group.failure = group.failure
+ failure
READ group$, Item$,
Lot$, qty, samples, failure
LOOP
PRINT
PRINT TAB(5); "****"; TAB(10); "Group
"; previous.group$; " Total";
PRINT TAB(35); USING "##,###
##,### ##,###"; group.qty; group.samples; group.failure
PRINT
grand.qty = grand.qty + group.qty
grand.samples = grand.samples + group.samples
grand.failure = grand.failure + group.failure
LOOP
RETURN
wrapup:
PRINT TAB(5); STRING$(61, "*")
PRINT TAB(5); "####"; TAB(10); "Grand total";
PRINT TAB(35); USING "##,###
##,### ##,###"; grand.qty; grand.samples; grand.failure;
PRINT " ####"
PRINT TAB(5); STRING$(61, "*")
RETURN
initialize:
cur.line
= 1
GOSUB
print.heading
grand.qty
= 0: grand.samples = 0: grand.failure = 0
READ
group$, item$, Lot$, qty, samples, failure
RETURN
print.heading:
PRINT
TAB(30); "Quality control report"
PRINT
TAB(5); "Group"; TAB(15); "Item"; TAB(25); "Lot"; TAB(35); "Qty";
PRINT
TAB(45); "Samples"; TAB(55); "Failure"; TAB(65); "Pass/Fail"
RETURN
process:
DO
UNTIL group$ = "eof"
group.qty
= 0: group.samples = 0: group.failure = 0
previous.group$
= group$
DO
UNTIL (group$ <> previous.group$) OR (group$ = "eof")
item.qty = 0: item.samples = 0: item.failure = 0
previous.item$ = item$
DO UNTIL (item$ <> previous.item$) OR (group$ <> previous.group$)
OR (group$ = "eof")
status$ = "Pass"
IF (failure / samples * 100) > 10 THEN
status$ = "Fail"
END IF
IF cur.line > 10 THEN
PRINT "Press any key to continue ..."
char$ = INPUT$(1)
CLS
GOSUB print.heading
cur.line = 1
END IF
cur.line = cur.line + 2
PRINT TAB(5); group$; TAB(15); item$; TAB(25); Lot$;
PRINT TAB(35); USING "##,### ##,###
##,###"; qty; samples; failure;
PRINT TAB(65); status$
item.qty = item.qty + qty
item.samples = item.samples + samples
item.failure = item.failure + failure
READ group$, item$, Lot$, qty, samples, failure
LOOP
PRINT
PRINT TAB(5); "****"; TAB(10); "Item "; previous.item$; " Total";
PRINT TAB(35); USING "##,### ##,###
##,###"; item.qty; item.samples; item.failure
PRINT
group.qty = group.qty + item.qty
group.samples = group.samples + item.samples
group.failure = group.failure + item.failure
LOOP
PRINT
PRINT
TAB(5); "****"; TAB(10); "Group "; previous.group$; " Total";
PRINT
TAB(35); USING "##,### ##,### ##,###";
group.qty; group.samples; group.failure
PRINT
grand.qty
= grand.qty + group.qty
grand.samples
= grand.samples + group.samples
grand.failure
= grand.failure + group.failure
LOOP
RETURN
wrapup:
PRINT TAB(5); STRING$(61, "*")
PRINT TAB(5); "####"; TAB(10); "Grand total";
PRINT TAB(35); USING "##,### ##,###
##,###"; grand.qty; grand.samples; grand.failure;
PRINT TAB(5); STRING$(61, "*")
RETURN