|
25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more... |
Home Projects Up Sitemap Search Blog Forum+Chat About Us Privacy Terms of Use Feedback FAQ Images Services Ads Donate Humor |
COMPARE This program is a bookkeeping aid for use in situations where the user has two sets of numbers that are supposed to be identical but are not, as is all too often the case. The program will help shorten the time needed to find the discrepancies between the two sets of numbers. The program is self-prompting. Carriage returns are not necessary after entering menu selections and answers to yes/no questions. Carriage returns are required after file name and numeric input. The user has the option of inputting either or both sets of numbers from previously created disk data files. The user also has the option of writing the two sets of numbers into data files, if it has not already been done. It is a good idea to use this option, since only through it can any changes be made to the files after the entry routine is over. During manual input of the numbers, the user should remember that entering "-9E9" will back up the entry by one number, and that "9E9" signals to the computer that the end of the list has been reached. Entering "-9E9" more than once will back up more than one entry. If either set of numbers will contain more than 500 elements, the variables A,B,C, and D should be redimensioned in line 190. An additional routine of the program (the "TAPE" routine) allows the display and manipulation of data AFTER it has been saved to a disk file. The routine allows printout of the raw data, insertion, deletion, and change of elements of the file. To insert a number as the first element of the file, the user must first insert the current first number after itself. Then, change the first-first number to the desired first number. The TAPE routine can be separated from the rest of the COMPARE program and used as a stand-alone in other situations. Since the manipulation routines search for particular occurrences of the numbers in question, they can also be used as handy general purpose search routines. In this case, you would, of course, change the searched number to the value it already has, and thus leave the list unchanged. 10 REM COMPARE.BAS 11 'COPYRIGHT (C)1982 STEVEN WHITNEY. 12 'Published under GNU GPL (General Public License) Version 2, with ABSOLUTELY NO WARRANTY. 13 'Initially published by http://25yearsofprogramming.com. 20 ON ERROR GOTO 2400 30 CLEAR 40 PRINT CHR$(27)"E" 50 PRINT "IF NOT ALREADY DONE, PLEASE PRESS THE 'CAPS LOCK' KEY ON YOUR KEYBOARD.":PRINT "ALL YOUR RESPONSES MUST BE CAPITAL LETTERS.":PRINT STRING$(75,"=") 60 PRINT,,"*** MENU ***":PRINT 70 PRINT,"1 = COMPARE TWO LISTS OF NUMBERS":PRINT 80 PRINT,"2 = VIEW OR CHANGE ONE OF THE LISTS":PRINT 90 PRINT,"3 = EXIT":PRINT:PRINT 100 PRINT"WHAT IS YOUR CHOICE?";:X$=INPUT$(1):PRINT X$:X=VAL(X$) 110 IF X<1 OR X>3 THEN 60 120 IF X=3 THEN END 130 PRINT CHR$(27)"E" 140 DEFINT I,J:DEFDBL A,B,C,D 150 ON X GOTO 160,1300 160 PRINT CHR$(27)"E";"This program compares two supposedly identical sets of numbers and prints":PRINT" out any discrepancies found between the sets.":PRINT 170 PRINT"If either set will contain over 500 numbers, abort execution and ":PRINT"redimension A,B,C and D in line 190." 180 PRINT "The two sets of numbers need not be the same length." 190 DIM A(500),B(500),C(500),D(500) 200 PRINT STRING$(75,"=") 210 PRINT"To re-enter a miskeyed number, enter -9E9 as the next number." 220 PRINT STRING$(75,"-") 230 I=0 240 PRINT:PRINT "Is either set of #'s to be retrieved from a disk file (Y/N)?";:X$=INPUT$(1):PRINT X$ 250 IF X$<>"Y" AND X$<>"N" THEN 240 260 IF X$="Y" THEN 1010 270 PRINT:PRINT TAB(20)"Input the first set of numbers.":PRINT 280 I=0 290 INPUT "(9E9 to end) Next #";A(I) 300 IF A(I)=-9000000000# THEN PRINT:PRINT "ERROR DETECTED. ";:I=I-1:PRINT"NUMBER WAS";A(I);" <NEXT ENTRY WILL REPLACE IT>":AS=AS-A(I):GOTO 290 310 IF A(I)=9000000000# THEN 350 320 AS=AS+A(I) 330 I=I+1 340 GOTO 290 350 PRINT CHR$(27)"E":PRINT"Now input the second set of numbers.":PRINT 360 J=0 370 INPUT "(9E9 to end) Next #";B(J) 380 IF B(J)=-9000000000# THEN PRINT "ERROR DETECTED. ";:J=J-1:PRINT"NUMBER WAS";B(J);" <NEXT ENTRY WILL REPLACE IT>":BS=BS-B(J):GOTO 370 390 IF B(J)=9000000000# THEN 430 400 BS=BS+B(J) 410 J=J+1 420 GOTO 370 430 REM COMPARISON SECTION 440 PRINT:PRINT,,"*** SYSTEM WORKING ***" 450 FOR K=0 TO I : C(K)=A(K) : NEXT K 460 FOR L=0 TO J : D(L)=B(L) : NEXT L 470 FOR K=0 TO I 480 FOR L=0 TO J 490 IF A(K)=B(L) THEN A(K)=9E+09 : B(L)=9E+09 : GOTO 510 500 NEXT L 510 NEXT K 520 REM REPORT SECTION 530 PRINT:PRINT "Do you want the report on paper? (Y/N)";:Z$=INPUT$(1):PRINT Z$ 540 IF Z$<>"Y" AND Z$<>"N" THEN 530 550 PRINT CHR$(27)"E":PRINT"These numbers appeared in the first set of numbers, but not in the second:" 560 IF Z$="Y" THEN LPRINT "These numbers appeared in the first set of numbers, but not in the second:" 570 PRINT STRING$(75,"-") 580 IF Z$="Y" THEN LPRINT STRING$(75,"-") 590 FOR K=0 TO I 600 IF A(K)<>9E+09 THEN A=A+A(K) : PRINT A(K), : IF Z$="Y" THEN LPRINT A(K), 610 NEXT K 620 PRINT:PRINT"Total of entire first set was==>";AS:PRINT,"Total of unmatched numbers==>";A 630 IF Z$="Y" THEN LPRINT:LPRINT"Total of entire first set was==>";AS:LPRINT,"Total of unmatched numbers==>";A 640 PRINT STRING$(75,"-") 650 IF Z$="Y" THEN LPRINT STRING$(75,"-") 660 PRINT"These numbers appeared in the second set of numbers, but not in the first:" 670 IF Z$="Y" THEN LPRINT "These numbers appeared in the second set of numbers, but not in the first:" 680 PRINT STRING$(75,"-") 690 IF Z$="Y" THEN LPRINT STRING$(75,"-") 700 FOR L=0 TO J 710 IF B(L)<>9E+09 THEN B=B+B(L) : PRINT B(L),:IF Z$="Y" THEN LPRINT B(L), 720 NEXT L 730 PRINT:PRINT"Total of entire second set was==>";BS:PRINT,"Total of unmatched numbers==>";B 740 IF Z$="Y" THEN LPRINT:LPRINT"Total of entire second set was==>";BS:LPRINT,"Total of unmatched numbers==>";B 750 PRINT STRING$(75,"-") 760 IF Z$="Y" THEN LPRINT STRING$(75,"-") 770 PRINT "Total discrepancy (=unmatched first-unmatched second)==>";A-B 780 IF Z$="Y" THEN LPRINT "Total discrepancy (=unmatched first-unmatched second)==>";A-B 790 PRINT STRING$(75,"=") 800 IF Z$="Y" THEN LPRINT STRING$(75,"=") 810 PRINT"If you plan to manipulate the data in any way, the lists must be saved on the":PRINT"disk. If they are not already there, you should save them now." 820 PRINT"Save the lists to the disk now (Y/N)?";:Z$=INPUT$(1):PRINT Z$ 830 IF Z$<>"Y" AND Z$<>"N" THEN 810 840 IF Z$<>"Y" THEN 1000 850 Q=1 860 PRINT:INPUT "NAME FOR FIRST FILE";L1$ 870 IF LEN(L1$)>8 AND LEFT$(RIGHT$(L1$,4),1)<>"." THEN PRINT "ONLY EIGHT CAPITAL LETTERS, PLEASE":GOTO 860 880 OPEN "O",1,L1$ 890 FOR K=0 TO I-1 900 PRINT #1,C(K) 910 NEXT K 920 CLOSE 930 PRINT:INPUT "NAME FOR SECOND FILE";L1$ 940 IF LEN(L1$)>8 AND LEFT$(RIGHT$(L1$,4),1)<>"." THEN PRINT "ONLY EIGHT CAPITAL LETTERS, PLEASE":GOTO 930 950 OPEN "O",1,L1$ 960 FOR L=0 TO J-1 970 PRINT #1,D(L) 980 NEXT L 990 CLOSE 1000 GOTO 1250 1010 PRINT:INPUT "Which file (including file type extension) holds the #'s";A$ 1020 OPEN "I",1,A$ 1030 I=-1 1040 WHILE NOT EOF(1) 1050 I=I+1 1060 INPUT #1,A(I) 1070 AS=AS+A(I) 1080 WEND 1090 CLOSE 1100 I=I+1 1110 PRINT:PRINT"Input the other set from a disk file (Y/N)?";:X$=INPUT$(1):PRINT X$ 1120 IF X$<>"Y" AND X$<>"N" THEN 1110 1130 IF X$="N" THEN 350 1140 PRINT:INPUT "Which file (including file type extension) holds the #'s";A$ 1150 OPEN "I",1,A$ 1160 J=-1 1170 WHILE NOT EOF(1) 1180 J=J+1 1190 INPUT #1,B(J) 1200 BS=BS+B(J) 1210 WEND 1220 CLOSE 1230 J=J+1 1240 GOTO 430 1250 PRINT:PRINT "If you find discrepancies caused by erroneous input, you can use the TAPE ":PRINT "routine to correct the problem." 1260 PRINT:PRINT "Do you want to transfer to the TAPE routine? (Y/N)";:X$=INPUT$(1):PRINT X$ 1270 IF X$<>"Y" AND X$<>"N" THEN 1260 1280 IF X$<>"Y" THEN END 1290 REM COPYRIGHT (C) 1982 STEVEN WHITNEY. 1300 REM PROGRAM NAME 'TAPE' 1310 REM COPYRIGHT (C) 1982 STEVEN WHITNEY. 1320 ON ERROR GOTO 2400 1330 CLEAR 1340 DEFDBL A,B : DEFINT I,J 1350 DIM A(500),C(500) 1360 PRINT CHR$(27)"E" 1370 INPUT "REFERENCE WHAT FILE (INCLUDING EXTENSION, IF ANY)";A$ 1380 OPEN "I",1,A$ 1390 WHILE NOT EOF(1) 1400 INPUT #1,A(I) 1410 I=I+1 1420 WEND 1430 CLOSE 1440 I=I-1 1450 REM MENU 1460 PRINT CHR$(27)"E" 1470 PRINT,,"*** MENU ***":PRINT 1480 PRINT,"1 = PRINT TAPE TO VIDEO SCREEN":PRINT 1490 PRINT,"2 = PRINT TAPE TO LINE PRINTER":PRINT 1500 PRINT,"3 = CHANGE A NUMBER":PRINT 1510 PRINT,"4 = DELETE A NUMBER":PRINT 1520 PRINT,"5 = INSERT A NUMBER":PRINT 1530 PRINT,"6 = UPDATE DISK FILE WITH THE NEW INFORMATION":PRINT 1540 PRINT,"7 = EXIT FROM PROGRAM":PRINT 1550 PRINT:PRINT:PRINT "WHAT IS YOUR CHOICE?";:X$=INPUT$(1):PRINT X$:X=VAL(X$) 1560 PRINT CHR$(27)"E" 1570 IF X<1 OR X>7 THEN 1450 1580 IF X=7 THEN GOTO 10 1590 ON X GOTO 1600,1600,1740,1870,2060,2300 1600 REM PRINT TAPE 1610 B=0 1620 PRINT "TAPE OF ";A$:PRINT 1630 IF X=2 THEN LPRINT "TAPE OF ";A$ 1640 FOR J=0 TO I 1650 PRINT A(J); 1660 IF X=2 THEN LPRINT A(J); 1670 B=B+A(J) 1680 NEXT J 1690 PRINT:PRINT"TOTAL = ";B 1700 IF X=2 THEN LPRINT:LPRINT "TOTAL = ";B 1710 PRINT "NUMBER OF ENTRIES = ";I+1 1720 IF X=2 THEN LPRINT "NUMBER OF ENTRIES =";I+1 1730 PRINT "PRESS ANY KEY TO CONTINUE":X$=INPUT$(1):GOTO 1450 1740 REM CHANGE A NUMBER 1750 PRINT:INPUT "WHAT WAS THE OLD (INCORRECT) NUMBER";W 1760 PRINT "NO ASTERISK WILL BE PRINTED IF THE OLD NUMBER IS NOT FOUND":PRINT 1770 FOR J=0 TO I 1780 PRINT A(J); 1790 IF A(J)<>W THEN PRINT: GOTO 1850 1800 PRINT "*":PRINT 1810 PRINT "THE ASTERISK MARKS THE NUMBER." 1820 PRINT "IS THIS THE CORRECT OCCURRANCE OF THE NUMBER (Y/N)?";:X$=INPUT$(1):PRINT X$ 1830 IF X$<>"Y" AND X$<>"N" THEN 1820 1840 IF X$="Y" THEN INPUT "CHANGE TO";A(J) : GOTO 1450 1850 NEXT J 1860 PRINT "NO CHANGE MADE":FOR K=1 TO 500:NEXT K : GOTO 1450 1870 REM DELETE A NUMBER 1880 PRINT:INPUT "WHAT IS THE NUMBER TO DELETE";W 1890 FOR J=0 TO I 1900 PRINT A(J); 1910 IF A(J)<>W THEN PRINT:GOTO 2030 1920 PRINT "*":PRINT 1930 PRINT "THE ASTERISK MARKS THE NUMBER." 1940 PRINT "IS THIS THE CORRECT OCCURRANCE?";:X$=INPUT$(1):PRINT X$ 1950 IF X$<>"Y" AND X$<>"N" THEN 1940 1960 IF X$<>"Y" THEN 2030 1970 FOR K=J TO I-1 1980 A(K)=A(K+1) 1990 NEXT K 2000 I=I-1 2010 PRINT "DELETION MADE":FOR K=1 TO 100:NEXT K : GOTO 1450 2020 GOTO 1450 2030 NEXT J 2040 PRINT "NO DELETION MADE":FOR K=1 TO 500:NEXT K 2050 GOTO 1450 2060 REM INSERT A NUMBER 2070 PRINT:INPUT "AFTER WHAT NUMBER DO YOU WANT TO MAKE THE INSERTION";W 2080 INPUT "WHAT NUMBER DO YOU WANT TO INSERT";N 2090 FOR J=0 TO I 2100 PRINT A(J); 2110 IF A(J)<>W THEN PRINT: GOTO 2270 2120 PRINT "*":PRINT 2130 PRINT "THE ASTERISK MARKS THE NUMBER." 2140 PRINT "INSERT AFTER THE ASTERISK (Y/N)?";:X$=INPUT$(1):PRINT X$ 2150 IF X$<>"Y" AND X$<>"N" THEN 2140 2160 IF X$<>"Y" THEN 2270 2170 FOR K=J+2 TO I+1 2180 C(K)=A(K-1) 2190 NEXT K 2200 A(J+1)=N 2210 FOR K=J+2 TO I+1 2220 A(K)=C(K) 2230 NEXT K 2240 I=I+1 2250 PRINT "INSERTION MADE":FOR K=1 TO 500:NEXT K 2260 GOTO 1450 2270 NEXT J 2280 PRINT "NO INSERTION MADE":FOR K=1 TO 500:NEXT K 2290 GOTO 1450 2300 REM UPDATE DISK FILE 2310 PRINT:INPUT "NAME FOR NEW FILE";A$ 2320 IF LEN(A$)>8 AND LEFT$(RIGHT$(A$,4),1)<>"." THEN PRINT "ONLY EIGHT CAPITAL LETTERS, PLEASE":GOTO 2310 2330 OPEN "O",1,A$ 2340 FOR J=0 TO I 2350 WRITE #1,A(J) 2360 NEXT J 2370 CLOSE 2380 PRINT "UPDATE MADE":FOR K=1 TO 1000:NEXT K 2390 GOTO 1450 2400 IF ERR<>53 THEN GOTO 2440 ELSE PRINT STRING$(75,"="):PRINT "ONLY THESE FILES ARE ON THE DISK:":PRINT:FILES:PRINT STRING$(75,"-") 2410 IF ERL=1020 THEN RESUME 1010 2420 IF ERL=1150 THEN RESUME 1140 2430 IF ERL=1380 THEN RESUME 1370 2440 PRINT "AN ERROR WAS ENCOUNTERED. PLEASE CONSULT YOUR BASIC-80 MANUAL REGARDING":PRINT "THE FOLLOWING ERROR MESSAGE. THE ERROR OCCURRED AT PROGRAM LINE #";ERL 2450 ON ERROR GOTO 0 2460 REM COPYRIGHT (C)1982 STEVEN WHITNEY.
|
|
|
|
|
|