Thanks - now works perfectly. Just needed to declare the sub at the beginning rather than in the code, just a tiny error. I think it is reading one character too much though?
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%
'*****Do I need anything past here? I don't think i do but it***********
'***************was in the origional guys code******************
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
That, as I say, works perfectly but I don't think I need the red stuff. tell me if i am wrong though please. The thing i am actually using it for is a hangman game. Just making it for fun. All I need to know now is how to get a random word from a random file - i posted a question on it but the replies don't seem to work. Thanls anyway whoever did post replies.
TP