'=========================================================================== ' Subject: CHARACTER COUNT OF TEXT FILES Date: 06-15-97 (22:23) ' Author: Ethan Eade Code: QB, QBasic, PDS ' Origin: ethaneade@toad.net Packet: TEXT.ABC '=========================================================================== DECLARE SUB printnumberofchars (chars() AS INTEGER, title AS STRING) DECLARE FUNCTION maxvalue (chars() AS INTEGER) DECLARE SUB calculate (chars() AS INTEGER) DECLARE SUB printer (multifilecount() AS INTEGER, allfiles() AS STRING) DIM multifilecount(1 TO 26) AS INTEGER DIM chars(1 TO 26) AS INTEGER DIM multifile(1 TO 10) AS STRING DIM allfiles(1 TO 10) AS STRING 1 : DO IF NOT nofileflag THEN filenumber = filenumber + 1 nofileflag = 0 SCREEN 0 CLS IF NOT filenumber = 1 THEN COLOR 14, 4: PRINT " Files processed:": COLOR 14, 0 FOR index = 1 TO 10 IF NOT allfiles(index) = "" THEN PRINT " "; allfiles(index) NEXT index PRINT END IF COLOR 14, 4: PRINT " Filename ("; CHR$(34); : COLOR 30: PRINT "quit"; : COLOR 14: PRINT CHR$(34); " to exit,"; CHR$(34); : COLOR 30: PRINT "print"; : COLOR 14: PRINT CHR$(34); " to print current values):"; COLOR , 0: INPUT " ", filename$ IF UCASE$(filename$) = "QUIT" THEN END IF UCASE$(filename$) = "PRINT" THEN CALL printer(multifilecount(), allfiles()): nofileflag = 1: GOTO 1 IF NOT MID$(filename$, 2, 2) = ":\" THEN filename$ = "c:\" + filename$ IF NOT nofileflag THEN allfiles(filenumber) = filename$ IF NOT filenumber = 1 AND NOT filenumber = 10 THEN multifile(filenumber) = ", " + filename$ ELSEIF filenumber = 1 THEN multifile(filenumber) = filename$ ELSEIF filenumber = 10 THEN multifile(filenumber) = ", and " + filename$ + "." END IF OPEN filename$ FOR INPUT AS #1 SCREEN 12 CALL calculate(chars()) FOR index = 1 TO 26 multifilecount(index) = multifilecount(index) + chars(index) NEXT index CALL printnumberofchars(chars(), "Results of file " + filename$) multifilenames$ = "" FOR index = 1 TO 10 'IF NOT nextline AND LEN(multifilenames$) > 15 THEN multifilenames$ = multifilenames$ + CHR$(13) + CHR$(10): nextline = 1 multifilenames$ = multifilenames$ + multifile(index) NEXT index IF NOT filenumber = 1 THEN CALL printnumberofchars(multifilecount(), "Results of Multifile Count of files " + multifilenames$) CLOSE (1) LOOP SUB calculate (chars() AS INTEGER) DIM hloc, lasthloc, module AS DOUBLE CLS hloc = 2 LINE (1, 20)-(639, 40), , B module = (1 / 638) * LOF(1) LOCATE 1, 1: COLOR 4: PRINT "Reading and Calculating...": COLOR 15 FOR index = 1 TO LOF(1) IF NOT INT((index / LOF(1)) * 100) = Percent THEN LOCATE 1, 36: PRINT INT((index / LOF(1)) * 100); "%": Percent = INT((index / LOF(1)) * 100) IF NOT index = LOF(1) AND index > (hloc - 1) * module THEN LINE (2, 21)-(hloc, 39), 1, BF: hloc = hloc + (1 / module) END IF IF index = LOF(1) THEN LINE (2, 21)-(638, 39), 1, BF char$ = INPUT$(1, 1) SELECT CASE UCASE$(char$) CASE "A": chars(1) = chars(1) + 1 CASE "B": chars(2) = chars(2) + 1 CASE "C": chars(3) = chars(3) + 1 CASE "D": chars(4) = chars(4) + 1 CASE "E": chars(5) = chars(5) + 1 CASE "F": chars(6) = chars(6) + 1 CASE "G": chars(7) = chars(7) + 1 CASE "H": chars(8) = chars(8) + 1 CASE "I": chars(9) = chars(9) + 1 CASE "J": chars(10) = chars(10) + 1 CASE "K": chars(11) = chars(11) + 1 CASE "L": chars(12) = chars(12) + 1 CASE "M": chars(13) = chars(13) + 1 CASE "N": chars(14) = chars(14) + 1 CASE "O": chars(15) = chars(15) + 1 CASE "P": chars(16) = chars(16) + 1 CASE "Q": chars(17) = chars(17) + 1 CASE "R": chars(18) = chars(18) + 1 CASE "S": chars(19) = chars(19) + 1 CASE "T": chars(20) = chars(20) + 1 CASE "U": chars(21) = chars(21) + 1 CASE "V": chars(22) = chars(22) + 1 CASE "W": chars(23) = chars(23) + 1 CASE "X": chars(24) = chars(24) + 1 CASE "Y": chars(25) = chars(25) + 1 CASE "Z": chars(26) = chars(26) + 1 END SELECT NEXT END SUB FUNCTION maxvalue (chars() AS INTEGER) FOR index = 1 TO 26 IF chars(index) > MAX THEN MAX = chars(index) NEXT index maxvalue = MAX END FUNCTION SUB printer (multifilecount() AS INTEGER, allfiles() AS STRING) LOCATE 15, 33: COLOR 30, 4: PRINT "Printing...": COLOR , 0 FOR index = 1 TO 26 total = total + multifilecount(index) NEXT index LPRINT " Total Character Count of the Following Files:" FOR index = 1 TO 10 IF NOT allfiles(index) = "" THEN LPRINT " " + allfiles(index) NEXT index LPRINT STRING$(75, "_") FOR index = 1 TO 26 LPRINT " Occurrences of character "; CHR$(index + 64); ": " + STR$(multifilecount(index)) + " Percentage of total characters: " + LEFT$(STR$(multifilecount(index) / total * 100), 5) NEXT index FOR index = 1 TO 32 LPRINT NEXT index END SUB SUB printnumberofchars (chars() AS INTEGER, title AS STRING) CLS module = 350 / maxvalue(chars()) FOR index = 1 TO 26 total = total + chars(index) LOCATE 29, index * 2 + 2: PRINT CHR$(index + 64); IF NOT chars(index) = 0 THEN LINE (index * 16 + 4, 445)-(index * 16 + 18, 445 - (module * chars(index))), 1, BF NEXT index LOCATE 1, 1: COLOR 4: PRINT title: COLOR 15 SELECT CASE UCASE$(INPUT$(1)) CASE "A": LOCATE 3, 25: PRINT CHR$(65); ":"; STR$(chars(1)): PRINT "Percent of all characters: " + STR$(chars(1) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "B": LOCATE 3, 25: PRINT CHR$(66); ":"; STR$(chars(2)): PRINT "Percent of all characters: " + STR$(chars(2) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "C": LOCATE 3, 25: PRINT CHR$(67); ":"; STR$(chars(3)): PRINT "Percent of all characters: " + STR$(chars(3) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "D": LOCATE 3, 25: PRINT CHR$(68); ":"; STR$(chars(4)): PRINT "Percent of all characters: " + STR$(chars(4) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "E": LOCATE 3, 25: PRINT CHR$(69); ":"; STR$(chars(5)): PRINT "Percent of all characters: " + STR$(chars(5) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "F": LOCATE 3, 25: PRINT CHR$(70); ":"; STR$(chars(6)): PRINT "Percent of all characters: " + STR$(chars(6) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "G": LOCATE 3, 25: PRINT CHR$(71); ":"; STR$(chars(7)): PRINT "Percent of all characters: " + STR$(chars(7) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "H": LOCATE 3, 25: PRINT CHR$(72); ":"; STR$(chars(8)): PRINT "Percent of all characters: " + STR$(chars(8) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "I": LOCATE 3, 25: PRINT CHR$(73); ":"; STR$(chars(9)): PRINT "Percent of all characters: " + STR$(chars(9) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "J": LOCATE 3, 25: PRINT CHR$(74); ":"; STR$(chars(10)): PRINT "Percent of all characters: " + STR$(chars(10) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "K": LOCATE 3, 25: PRINT CHR$(75); ":"; STR$(chars(11)): PRINT "Percent of all characters: " + STR$(chars(11) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "L": LOCATE 3, 25: PRINT CHR$(76); ":"; STR$(chars(12)): PRINT "Percent of all characters: " + STR$(chars(12) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "M": LOCATE 3, 25: PRINT CHR$(77); ":"; STR$(chars(13)): PRINT "Percent of all characters: " + STR$(chars(13) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "N": LOCATE 3, 25: PRINT CHR$(78); ":"; STR$(chars(14)): PRINT "Percent of all characters: " + STR$(chars(14) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "O": LOCATE 3, 25: PRINT CHR$(79); ":"; STR$(chars(15)): PRINT "Percent of all characters: " + STR$(chars(15) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "P": LOCATE 3, 25: PRINT CHR$(80); ":"; STR$(chars(16)): PRINT "Percent of all characters: " + STR$(chars(16) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "Q": LOCATE 3, 25: PRINT CHR$(81); ":"; STR$(chars(17)): PRINT "Percent of all characters: " + STR$(chars(17) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "R": LOCATE 3, 25: PRINT CHR$(82); ":"; STR$(chars(18)): PRINT "Percent of all characters: " + STR$(chars(18) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "S": LOCATE 3, 25: PRINT CHR$(83); ":"; STR$(chars(19)): PRINT "Percent of all characters: " + STR$(chars(19) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "T": LOCATE 3, 25: PRINT CHR$(84); ":"; STR$(chars(20)): PRINT "Percent of all characters: " + STR$(chars(20) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "U": LOCATE 3, 25: PRINT CHR$(85); ":"; STR$(chars(21)): PRINT "Percent of all characters: " + STR$(chars(21) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "V": LOCATE 3, 25: PRINT CHR$(86); ":"; STR$(chars(22)): PRINT "Percent of all characters: " + STR$(chars(22) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "W": LOCATE 3, 25: PRINT CHR$(87); ":"; STR$(chars(23)): PRINT "Percent of all characters: " + STR$(chars(23) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "X": LOCATE 3, 25: PRINT CHR$(88); ":"; STR$(chars(24)): PRINT "Percent of all characters: " + STR$(chars(24) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "Y": LOCATE 3, 25: PRINT CHR$(89); ":"; STR$(chars(25)): PRINT "Percent of all characters: " + STR$(chars(25) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE "Z": LOCATE 3, 25: PRINT CHR$(90); ":"; STR$(chars(26)): PRINT "Percent of all characters: " + STR$(chars(26) / total * 100) + "%" + SPACE$(50 - POS(1)): LOCATE 3, 1: PRINT "Occurrences of character"; CASE CHR$(27): EXIT SUB CASE " ": EXIT SUB END SELECT DO SELECT CASE UCASE$(INPUT$(1)) CASE "A": LOCATE 3, 25: PRINT CHR$(65); ":"; STR$(chars(1)): PRINT "Percent of all characters: " + STR$(chars(1) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "B": LOCATE 3, 25: PRINT CHR$(66); ":"; STR$(chars(2)): PRINT "Percent of all characters: " + STR$(chars(2) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "C": LOCATE 3, 25: PRINT CHR$(67); ":"; STR$(chars(3)): PRINT "Percent of all characters: " + STR$(chars(3) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "D": LOCATE 3, 25: PRINT CHR$(68); ":"; STR$(chars(4)): PRINT "Percent of all characters: " + STR$(chars(4) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "E": LOCATE 3, 25: PRINT CHR$(69); ":"; STR$(chars(5)): PRINT "Percent of all characters: " + STR$(chars(5) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "F": LOCATE 3, 25: PRINT CHR$(70); ":"; STR$(chars(6)): PRINT "Percent of all characters: " + STR$(chars(6) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "G": LOCATE 3, 25: PRINT CHR$(71); ":"; STR$(chars(7)): PRINT "Percent of all characters: " + STR$(chars(7) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "H": LOCATE 3, 25: PRINT CHR$(72); ":"; STR$(chars(8)): PRINT "Percent of all characters: " + STR$(chars(8) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "I": LOCATE 3, 25: PRINT CHR$(73); ":"; STR$(chars(9)): PRINT "Percent of all characters: " + STR$(chars(9) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "J": LOCATE 3, 25: PRINT CHR$(74); ":"; STR$(chars(10)): PRINT "Percent of all characters: " + STR$(chars(10) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "K": LOCATE 3, 25: PRINT CHR$(75); ":"; STR$(chars(11)): PRINT "Percent of all characters: " + STR$(chars(11) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "L": LOCATE 3, 25: PRINT CHR$(76); ":"; STR$(chars(12)): PRINT "Percent of all characters: " + STR$(chars(12) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "M": LOCATE 3, 25: PRINT CHR$(77); ":"; STR$(chars(13)): PRINT "Percent of all characters: " + STR$(chars(13) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "N": LOCATE 3, 25: PRINT CHR$(78); ":"; STR$(chars(14)): PRINT "Percent of all characters: " + STR$(chars(14) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "O": LOCATE 3, 25: PRINT CHR$(79); ":"; STR$(chars(15)): PRINT "Percent of all characters: " + STR$(chars(15) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "P": LOCATE 3, 25: PRINT CHR$(80); ":"; STR$(chars(16)): PRINT "Percent of all characters: " + STR$(chars(16) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "Q": LOCATE 3, 25: PRINT CHR$(81); ":"; STR$(chars(17)): PRINT "Percent of all characters: " + STR$(chars(17) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "R": LOCATE 3, 25: PRINT CHR$(82); ":"; STR$(chars(18)): PRINT "Percent of all characters: " + STR$(chars(18) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "S": LOCATE 3, 25: PRINT CHR$(83); ":"; STR$(chars(19)): PRINT "Percent of all characters: " + STR$(chars(19) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "T": LOCATE 3, 25: PRINT CHR$(84); ":"; STR$(chars(20)): PRINT "Percent of all characters: " + STR$(chars(20) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "U": LOCATE 3, 25: PRINT CHR$(85); ":"; STR$(chars(21)): PRINT "Percent of all characters: " + STR$(chars(21) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "V": LOCATE 3, 25: PRINT CHR$(86); ":"; STR$(chars(22)): PRINT "Percent of all characters: " + STR$(chars(22) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "W": LOCATE 3, 25: PRINT CHR$(87); ":"; STR$(chars(23)): PRINT "Percent of all characters: " + STR$(chars(23) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "X": LOCATE 3, 25: PRINT CHR$(88); ":"; STR$(chars(24)): PRINT "Percent of all characters: " + STR$(chars(24) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "Y": LOCATE 3, 25: PRINT CHR$(89); ":"; STR$(chars(25)): PRINT "Percent of all characters: " + STR$(chars(25) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE "Z": LOCATE 3, 25: PRINT CHR$(90); ":"; STR$(chars(26)): PRINT "Percent of all characters: " + STR$(chars(26) / total * 100) + "%" + SPACE$(50 - POS(1)) CASE CHR$(27): EXIT SUB CASE " ": EXIT SUB END SELECT LOOP END SUB