1,105,380 Community Members

QBasic character counter - helped by Buff

Member Avatar
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

This is a little program in QBasic which counts the number of characters in a string. Made by Buff - two errors removed by me. Thanks Buff.

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 is John Doe"
GetWords xst$, words%
PRINT "words= "; words%

SUB GetWords (st$, wds%)
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%
wds% = words%
END SUB

Member Avatar
Dani
The Queen of DaniWeb
20,568 posts since Feb 2002
Reputation Points: 1,356 [?]
Q&As Helped to Solve: 931 [?]
Skill Endorsements: 204 [?]
Administrator
Featured
Sponsor
 
0
 

Thank you ... and thank Buff. Who is Buff ;)

Member Avatar
rhenerlau
Newbie Poster
9 posts since Apr 2005
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

The Len() function is all you really need

You
Post:
Start New Discussion
Tags Related to this Article