Program: Cnttext.bas

Implementation Select: Implementation
Operation Select: Program: CNTTEXT.BAS
DECLARE SUB PROCESS (item!)
DIM SHARED countarray(26), letterarray$(26)
DIM SHARED textstring$
DIM SHARED textletter$, alphabetletter$

' Program calculates how often each letter appears in a sentence
'                     CNTTEXT.BAS
'      Revision 1.0   Original                               21 Apr 2000

CLS
' Initialize letterarray with alphabet
FOR i = 1 TO 26
   letterarray$(i) = CHR$(ASC("a") + i - 1)
NEXT i

INPUT "Enter sentence"; textstring$
l = LEN(textstring$)
IF l = 0 THEN END
FOR i = 1 TO l
  textletter$ = MID$(textstring$, i, 1)
  FOR item = 1 TO 26
    alphabetletter$ = letterarray$(item)
    PROCESS item
  NEXT item
NEXT i

' Print result from high to low
DO
  maxi = 1: maxcount = countarray(maxi)
  FOR i = 2 TO 26
    IF countarray(i) > maxcount THEN
       maxi = i: maxcount = countarray(i)
    END IF
  NEXT i
  IF maxcount > 0 THEN PRINT letterarray$(maxi), countarray(maxi)
  countarray(maxi) = 0
LOOP UNTIL maxcount = 0

SUB PROCESS (item)
  ' PRINT alphabetletter$, textletter$
  IF UCASE$(alphabetletter$) = UCASE$(textletter$) THEN
     countarray(item) = countarray(item) + 1
  END IF
END SUB


Back to my home page Contents of This Document