MX6CAT Posted November 12, 2003 Posted November 12, 2003 (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 November 12, 2003 by Robby Quote
Leaders Iceplug Posted November 12, 2003 Leaders Posted November 12, 2003 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. Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Moderators Robby Posted November 12, 2003 Moderators Posted November 12, 2003 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. Quote Visit...Bassic Software
MX6CAT Posted November 12, 2003 Author Posted November 12, 2003 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? Quote
MX6CAT Posted November 12, 2003 Author Posted November 12, 2003 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. Quote
MX6CAT Posted November 13, 2003 Author Posted November 13, 2003 I tried what i just posted and its counting every character (letters and spaces) rather then every word HELP plz :( Quote
MX6CAT Posted November 13, 2003 Author Posted November 13, 2003 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) Quote
Leaders Iceplug Posted November 13, 2003 Leaders Posted November 13, 2003 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). :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.