home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form WordCountForm
- Caption = "Counting Words"
- ClientHeight = 4485
- ClientLeft = 60
- ClientTop = 345
- ClientWidth = 6975
- LinkTopic = "Form1"
- ScaleHeight = 4485
- ScaleWidth = 6975
- StartUpPosition = 3 'Windows Default
- Begin VB.CommandButton Command1
- Caption = "Count Words"
- BeginProperty Font
- Name = "Verdana"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 495
- Left = 4800
- TabIndex = 1
- Top = 3840
- Width = 2055
- End
- Begin VB.TextBox Text1
- BeginProperty Font
- Name = "Verdana"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 3495
- Left = 120
- MultiLine = -1 'True
- TabIndex = 0
- Text = "WCount.frx":0000
- Top = 120
- Width = 6735
- End
- Attribute VB_Name = "WordCountForm"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Private Sub Command1_Click()
- Dim position As Long
- Dim words As Long
- Dim myText As String
- position = 1
- myText = Text1.Text
- ' massage string:
- ' replace line feeds with spaces
- myText = Replace(myText, Chr(13) & Chr(10), " ")
- ' replace tabs with single spaces
- myText = Replace(myText, Chr(9), " ")
- myText = Trim(myText)
- ' Count the first word
- ' Because the last word isn't delimited by
- ' a space, if the string isn't blank, then it
- ' contains at least one word.
- ' By setting words=1, we won't have to increase the
- ' number of words by 1 when we are done counting.
- If Len(myText) > 0 Then words = 1
- ' while the string contains spaces...
- Do While position > 0
- position = InStr(position, myText, " ")
- ' ... increase word count
- If position > 0 Then
- words = words + 1
- ' and skip additional spaces
- While Mid(myText, position, 1) = " "
- position = position + 1
- Wend
- End If
- Loop
- MsgBox "The TextBox contains " & words & " words"
- End Sub
-