|
Visual Basic (VB and VBA) |
|
Copyright 1999-2001 Christopher Greaves. All rights reserved. Home Page and email to [email protected] |
| If in doubt, record a macro and inspect the entrails! |
Please read the DISCLAIMER.
Here is an INDEX to all the procedures.
You will probably need one copy of my GLOBAL DECLARATIONS.
Public Function intCountWords(strText As String, strDelimiter As String) As Integer
' Procedure : intCountWords
' Description: Extract a text string from a named document.
' Copyright: Chris Greaves Inc.
' Inputs: A string to be examine, a string delimiter character
' Returns: String
' Assumes: Nothing
' Side Effects: None.
' Tested: By the calls shown below.
' Squeeze out multiple occurrences of the delimiter character.
Dim strLocal As String
Dim strOldLocal As String
strLocal = strText
strLocal = strReplaceAll(strText, strDelimiter & strDelimiter, strDelimiter)
While strOldLocal <> strLocal
strOldLocal = strLocal
strLocal = strReplaceAll(strLocal, strDelimiter & strDelimiter, strDelimiter)
Wend
strLocal = Trim(strLocal)
intCountWords = 0
Dim intOldI As Integer
Dim intI As Integer
intI = 1
While intI > intOldI ' until we have gone past the end of the string
intCountWords = intCountWords + 1
intOldI = intI
intI = InStr(intI, strLocal, strDelimiter) + 1
Wend
'Sub TESTintCountWords()
'MsgBox intCountWords("here is a sample string", " ")
'MsgBox intCountWords(" here is a sample string ", " ")
'MsgBox intCountWords(" here is a sample string", " ")
'MsgBox intCountWords(" here is a sample string", " ")
'End Sub
End Function
| We all knew nothing when we started … |
|
Home Page and Contact Information Send email to [email protected]. This page was last updated Thursday, November 15, 2001 |