3

I have an example of a program that shows how to set up a counter for how many times each letter of the alphabet was used. I don't understand the syntax of the middle portion of the program.

LET letter$ = MID$(sentence$, LETTERNUMBER, 1)

I have tried searching on youtube and tutorials online

CLS
REM Make Counters for each Letter!!!
DIM Count(ASC("A") TO ASC("Z"))
REM Get the Sentence
INPUT "Enter Sentence:", sentence$
LET sentence$ = UCASE$(sentence$)
FOR I = ASC("A") TO ASC("Z")
    LET Count(I) = 0
NEXT I

FOR LETTERNUMBER = 1 TO LEN(sentence$)
    LET letter$ = MID$(sentence$, LETTERNUMBER, 1)
    IF (letter$ >= "A") AND (letter$ <= "Z") THEN
        LET k = ASC(letter$)
        LET Count(k) = Count(k) + 1
    END IF
NEXT LETTERNUMBER
PRINT

REM Display These Counts Now
LET letterShown = 0
FOR letternum = ASC("A") TO ASC("Z")
    LET letter$ = CHR$(letternum)
    IF Count(letternum) > 0 THEN
        PRINT USING "\\##   "; letter$; Count(letternum);
    END IF
    LET letterShown = letterShown + 1
    IF letterShown = 7 THEN
        PRINT
        LET letterShown = 0
    END IF
NEXT letternum
END

A through Z appears with the count of how many times they appeared.

Dale K
  • 25,246
  • 15
  • 42
  • 71

2 Answers2

2

The MID$ function returns a portion of a STRING's value from any position inside a string.

Syntax:

    MID$(stringvalue$, startposition%[, bytes%]) 

Parameters:

  • stringvalue$

    can be any literal or variable STRING value having a length. See LEN.

  • startposition%

    designates the non-zero position of the first character to be returned by the function.

  • bytes%

    (optional) tells the function how many characters to return including the first character when it is used.

eoredson
  • 1,167
  • 2
  • 14
  • 29
1

Another method to calculate characters in a string:

REM counts and displays characters in a string
DIM count(255) AS INTEGER
PRINT "Enter string";: INPUT s$
' parse string
FOR s = 1 TO LEN(s$)
    x = ASC(MID$(s$, s, 1))
    count(x) = count(x) + 1
NEXT
' display string values
FOR s = 1 TO 255
    PRINT s; "="; count(s); " ";
    IF (s MOD 8) = 0 THEN
        PRINT
        IF (s MOD 20) = 0 THEN
            PRINT "Press key:";
            WHILE INKEY$ = "": WEND: PRINT
        END IF
    END IF
NEXT
END
eoredson
  • 1,167
  • 2
  • 14
  • 29