Word Count Program in VB,NET

For this article, we will create a program that will count the number of words in a TextBox. But we will just use the RichTextBox instead of TextBox :) Now, let's start this tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add one RichTextBox named RichTextBox1 and a Button named Button1 labeled as "Get Number of Words". You must design your layout like this: design 3. Now put add this code for your code module. This code is for Button1_Click. This will trigger to count the number of words in your RichTextBox.
  1.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim strInput As String
  3.         strInput = RichTextBox1.Text
  4.         Dim strSplit() As String
  5.         strSplit = strInput.Split(CChar(" "))
  6.         MsgBox("Number of words: " & strSplit.Length)
  7.     End Sub

Explanation:

We have initialized variable strInput as String to hold the value inputted in the RichTextBox. We also declare variable strSplit as string to split the words inputted in the RichTextBox. We use the CChar function to find the spacing of the text. Then we create a MessageBox to display the number of words using the Length function.

Output:

output 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. Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz

Comments

The only problem is by default it gives a 1 word even if there are no words in the rich text box, i am not sure how to set it from 0 and beyong.

Add new comment