Count Number of Characters in VB.NET

In this article, we will create a program that can count all the characters of a text inputted in a TextBox in vb.net. I already made a tutorial this one in vb 6.0 but it has complexity of code. 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 only one Button named Button1 and labeled it as "Count Characters". Add also TextBox named TextBox1 for our input. You must design your interface like this: design 3.Now put this code for your code module. This code is for Button1_Click:
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Dim strLength As String = TextBox1.Text
  3. MessageBox.Show("Number of Characters: " & strLength.Length.ToString)
  4. End Sub

Explanation:

We have initialized first a variable that will hold the value/string inputted in our textbox and we named it strLength as a String variable. Then we have created a messagebox that will display the total number of characters in the inputted textbox. The strLength variable with its length it returns the count of attributes for an element of the textbox. We have the ToString property also that converts the length of the textbox to its string representation so that it is suitable for display.

Output:

output Download the source code below and try it! :) For more inquiries just contact my number or e-mail 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

what if i want to count all the numbers and characters input in 2 different value one for the numbers and for the characters

Add new comment