| | |
Word Count Help !!
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
I hope it could help.
Bye!
vb Syntax (Toggle Plain Text)
Private Function CountWords(strText As String) As Long Dim x As Long Dim words As Long Dim lenStr As Long Dim lenPrevWord As Long Dim currentAscii As Integer ' Number of chars in string lenStr = Len(strText) ' Number of chars in the last word processed lenPrevWord = 0 For x = 1 To lenStr ' ASCII value of the char being processed currentAscii = Asc(Mid$(strText, x, 1)) Select Case currentAscii ' If current char is space (ASCII value 32)... Case 32 ' ...and we have processed at least a char before ' then we have found a word If lenPrevWord > 0 Then words = words + 1 ' Clear count of characters in previous word lenPrevWord = 0 End If Case Else ' If current char is not a space, then add 1 to the ' count of chars of the current word. lenPrevWord = lenPrevWord + 1 End Select ' Test if last char is other than a space. ' If so then there is a word. If x = lenStr And currentAscii <> 32 Then words = words + 1 End If Next x CountWords = words End Function
•
•
Join Date: Feb 2007
Posts: 16
Reputation:
Solved Threads: 1
•
•
•
•
I have uploaded a sample VB6 project to demonstrate the use of this function.
but just now i came up with something:
Private Sub cmd_Click()
txt = txt.Text
txt.Text = Trim$(txt.Text)
spacecount = 1
For x = 1 To Len(txt)
If Mid(txt, x, 1) = " " Then spacecount = spacecount + 1
Next
MsgBox spacecount & " words found."
End Sub
This program does not count the number of words but the number of spaces. This will work too if i can just get it to stop counting the extra spaces as words betweeen words.
Hi,
Just use this simple Code:
I hope it is clear.
Regards
Veena :lol:
Just use this simple Code:
Private Sub CmdCount_Click()
Dim MyCntArray
Dim MyStr As String
Dim i As Integer
'
MyStr = TextBox1.Text
'
For i = 2 To 10
MyStr = Replace(MyStr, Space(i), Space(1))
Next
' Replace All the multiple Spaces with single spaces
' here i have given for max 10 spaces,
' u can change it to a higher value
'
MyCntArray = Split(MyStr, " ")
MsgBox "Number Of Words : " & UBound(MyCntArray) - 1
'
End SubI hope it is clear.
Regards
Veena :lol:
![]() |
Similar Threads
- word count (C++)
- Word count help. (C++)
- Can you please help me write this word count program in another way (Python)
- I Need Help Writing A Word Count Program In My Python (Python)
- Need Help, basic word count, string manipulation (VB.NET)
- word count in borland c++ ?? (C++)
- word count (Java)
- I can't implement a word count into my text editor (JAVA) (Java)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Saving Excel Worksheet
- Next Thread: Questions Unsolvable
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






