|
-
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
-
Nov 6th, 2000, 05:27 PM
#2
_______
<?>
I find that to be reverse of what happens for me.
I get one less than the count of words. If there are 8 words I get sever so you need to add one to count and the reason you have to do that is because there is no " " at the end of the string but there is a word between the last " " and the end of the string.
You also don't need the i = i + 1 as the loop self increments.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 6th, 2000, 05:28 PM
#3
_______
<?>
I forgot..if you lhave any double spaces your count will be wrong as well.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 6th, 2000, 05:31 PM
#4
Thread Starter
Lively Member
-
Nov 6th, 2000, 05:35 PM
#5
-
Nov 6th, 2000, 05:37 PM
#6
Thread Starter
Lively Member
OH IT DOES!!!!!!
thanks a lot it works perfectly, but i had posted that earlier so i thought i might as well try to figure out what was wrong with my code
-
Nov 6th, 2000, 06:39 PM
#7
_______
<?>
mykg4orce
Use the split funtion as recommended in your second post as it doesn't have that problem.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
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
|