'************************************** ' Name: Count Words In a Texbox ' Description:This code will count the n ' umber of words in a textbox. A friend as ' ked how to do this so I thought I'd post ' my reply. ' By: Oliver French (from psc cd) ' ' ' Inputs:Any string. ' ' Returns:The number of words in the str ' ing. ' 'Assumes:Assumes a word is any set of ch ' aracters separated by a space. The code ' can be easily modified to use any deline ' ators. ' 'Side Effects:None '************************************** <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <SCRIPT LANGUAGE = VBSCRIPT> <!-- sub AddWords() dim strWhole dim x dim i dim currentLetter dim prevLetter dim total strWhole = Trim(form1.txtString.value) ' Remove leading and trailing spaces of string if any. if strWhole = "" then ' The text box is empty. msgbox "There are no words in the text box!" exit sub end if x = Len(strWhole) ' Store the total number of letters in the string. total = 1 ' Start the count at one. ' Loop through the string two letters at a time. If the current letter is a space, and the previous ' letter was not a space, then another word is counted. For i = 2 to x currentLetter = mid(strWhole, i, 1) prevLetter = mid(strWhole, i - 1, 1) if currentLetter = Chr(32) and prevLetter <> Chr(32) then total = total + 1 end if next msgbox "There are " & total & " words in the text box." end sub ' --> </Script> </head> <body bgcolor="#FFFFFF" text="#000000"> <p>Enter the string you wish counted:</p> <form name="form1" method="post" action=""> <p> <textarea name=txtString rows=5 cols=51></textarea> </p> <p>&nbsp;</p> <p> <input type="button" name="cmdExecute" value="Add Words" onclick=AddWords()> </p> <p>&nbsp;</p> </form> </body> </html>