Quick Basic in Application

Posts Tagged ‘Counter

Qbasic Character Counter

Posted by: programmervb on: March 6, 2009

DECLARE SUB GetWords (st$, wds%)
st$ = “Hello my name is John Doe”
IF RIGHT$(st$, 1) <> ” ” THEN st$ = st$ + ” “
FOR k% = 1 TO LEN(st$)
IF MID$(st$, k%, 1) = ” ” THEN words% = words% + 1
characters% = characters% + 1
NEXT
PRINT “total characters=”; characters%
PRINT “total words=”; words%
xst$ = “Hello my name [...]

Tags: