|
-
Nov 6th, 2000, 05:16 PM
#1
Thread Starter
Lively Member
this is the code i have to count words from a text field
the text field has 72 words but this code keeps returning 73, i know that i can minus 1 from the counter to give the right answer but that is cheap, please tell me if there is a easier way of doing this, i am using VB version 5.0
Option Explicit
Dim LineOfText, SingleCharacter As String
Dim i As Integer
Dim Counter As Integer
Counter = 0
For i = 1 To Len(LineOfText)
SingleCharacter = Mid$(LineOfText, i, 2)
If SingleCharacter = " " Then
Counter = Counter + 1
Else
SingleCharacter = Mid$(LineOfText, i, 1)
If SingleCharacter = " " Then
Counter = Counter + 1
i = i + 1
End If
End If
Next i
lblTotalWords.Caption = Counter
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|