User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Legacy and Other Languages section within the Software Development category of DaniWeb, a massive community of 402,639 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,228 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Legacy and Other Languages advertiser: Programming Forums
Jan 1st, 2005
Views: 3,563
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.
qbasic Syntax | 4 stars
  1. DECLARE SUB GetWords (st$, wds%)
  2.  
  3. st$ = "Hello my name is John Doe"
  4. IF RIGHT$(st$, 1) <> " " THEN st$ = st$ + " "
  5. FOR k% = 1 TO LEN(st$)
  6. IF MID$(st$, k%, 1) = " " THEN words% = words% + 1
  7. characters% = characters% + 1
  8. NEXT
  9. PRINT "total characters="; characters%
  10. PRINT "total words="; words%
  11.  
  12.  
  13. xst$ = "Hello my name is John Doe"
  14. GetWords xst$, words%
  15. PRINT "words= "; words%
  16.  
  17. SUB GetWords (st$, wds%)
  18. IF RIGHT$(st$, 1) <> " " THEN st$ = st$ + " "
  19. FOR k% = 1 TO LEN(st$)
  20. IF MID$(st$, k%, 1) = " " THEN words% = words% + 1
  21. characters% = characters% + 1
  22. NEXT
  23. 'print "total characters=";characters%
  24. 'print "total words=";words%
  25. wds% = words%
  26. END SUB
  27.  
  28.  
Comments (Newest First)
rhenerlau | Newbie Poster | Apr 22nd, 2005
The Len() function is all you really need
cscgal | The Queen of DaniWeb | Jan 1st, 2005
Thank you ... and thank Buff. Who is Buff
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 2:19 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC