Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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...

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*

Edited by Robby
  • Leaders
Posted

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.

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

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?

Posted

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.

Posted

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)

  • Leaders
Posted

It looks like it should count one word less than what you already have. In this case, you could just initialize intCount to 1 (or -1).

:)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...