Word Count Program in VB6
Submitted by donbermoy on Thursday, March 13, 2014 - 22:14.
In my previous tutorials, I had also discussed about how to have an word count using vb.net. And for now, we will create another version of this program that can count the number of words using vb6.0.
Now, let's start this tutorial!
1. Let's start this tutorial by following the following steps in Microsoft Visual Basic 6.0: Open Microsoft Visual Basic 6.0, click Choose Standard EXE, and click Open.
2.Next, add only one Button named Count Number of Words and labeled it as "Compute". Add also one TextBox named Text1 that will serve as your input to write your sentence.You must design your interface like this:
3. Now put this code for your code module. This code is for Command1_Click:
Download the source code and try it! :)
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below and hire me.
Best Regards,
Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
STI College - Surigao City
Mobile: 09488225971
E-mail:[email protected]
Follow and add me in my Facebook Account: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

- Private Sub Command1_Click()
- Dim tmpNum As Integer
- Const onespace As String = " "
- Const twospace As String = " "
- Dim tmpWords() As String
- Dim tmpText As String
- tmpNum = -1
- tmpText = Text1.Text
- Do Until tmpNum = 0
- tmpNum = InStr(tmpText, twospace)
- If tmpNum > 0 Then
- tmpText = Replace(tmpText, twospace, onespace)
- End If
- Loop
- tmpWords = Split(tmpText, onespace)
- MsgBox "Number of Words: " & UBound(tmpWords) + 1
- End Sub
Explanation:
We have initialized variable tmpNum As Integer will be equal to -1,tmpText As String will hold the inputted text in the textbox,tmpWords() As String Array, constant variable onespace As String is equal to one space, and constant variable twospace As String is equal to two spaces. Next, we have created a Do Until loop that us until tmpNum is equal to 0. Then tmpNum will hold the value of inserting a two space in tmpText variable. If tmpNum > 0 then tmpText will now hold the value of tmpText with one space. Replace method returns a string in which a specified substring has been replaced with another substring a specified number of times. Then variable tmpWords as an array will hold the split value of tmpText with onespace. Split Function returns a zero-based, one-dimensional array containing a specified number of substrings. Then, tmpWords will now hold the array elements that has the number of words. UBound fuction returns the highest available subscript for the indicated dimension of an array.Output:

Comments
Add new comment
- Add new comment
- 615 views