Word count with Flags?

MX6CAT

Newcomer
Joined
Nov 12, 2003
Messages
5
I need help. I am doing a project to count words in a Text box. But i cannot use that Split thing i searched about. I need to use flags but i can't figure a way to have it notice a flag true to false change. So far is this all i have...
Visual Basic:
Dim i As Integer
        Dim bolflag As Boolean
        Dim strChar As String
        Dim strWords As String
        Dim intCount As Integer
        strWords = txtWordsToCount.Text
        bolflag = False
        For i = 0 To strWords.Length - 1
            strChar = strWords.Substring(i, 1)
            If strChar = " " Then
                bolflag = True
            End If
            'If bolflag = False Then
            'intCount += 1
            'End If
        Next
I would appreciate ANY help. FAST hehe thanx!
*CAT*
 
Last edited by a moderator:
You had it. All you needed to do was set the Flag back to false immediately after you checked it. :)

And, you want to check if the flag is True, not False. False means it's down, and you almost never want to check that.
 
Why can't you use the split function?

If you absolutly aren't allowed to use the Split then using the code you have get rid of the bolFlag and place a counter there.
 
okay where would i place the counter? I have to account for multiple spaces etc. its just a bit confusing.
is this looking right? do i need to Dim i As Integer
Dim bolflag As Boolean
Dim strChar As String
Dim strWords As String
Dim intCount As Integer
strWords = txtWordsToCount.Text
bolflag = False
For i = 0 To strWords.Length - 1
strChar = strWords.Substring(i, 1)
If strChar = " " Then
bolflag = True
End If
bolflag = False
intCount += 1
Nextdo more?
 
okay where would i place the counter? I have to account for multiple spaces etc. its just a bit confusing.
is this looking right? do i need to do more?
Dim i As Integer
Dim bolflag As Boolean
Dim strChar As String
Dim strWords As String
Dim intCount As Integer
strWords = txtWordsToCount.Text
bolflag = False
For i = 0 To strWords.Length - 1
strChar = strWords.Substring(i, 1)
If strChar = " " Then
bolflag = True
End If
bolflag = False
intCount += 1
Next

sorry taht last post got all messed up.
 
I tried what i just posted and its counting every character (letters and spaces) rather then every word HELP plz :(
 
Okay i fixed it a bit more but it still counts one more word than i really have

Dim i As Integer
Dim bolflag As Boolean
Dim strChar As String
Dim strWords As String
Dim intCount As Integer
strWords = txtWordsToCount.Text
bolflag = False
For i = 0 To strWords.Length - 1
strChar = strWords.Substring(i, 1)
If strChar = " " Then
bolflag = True
End If
If bolflag Then
bolflag = False
intCount += 1
End If
Next
lblDisplayCount.Text = CStr(intCount)
 
Back
Top