Count Number of Characters in VB.NET
Submitted by donbermoy on Monday, April 7, 2014 - 22:09.
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:
3.Now put this code for your code module. This code is for Button1_Click:
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim strLength As String = TextBox1.Text
- MessageBox.Show("Number of Characters: " & strLength.Length.ToString)
- 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:
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
Add new comment
- Add new comment
- 4687 views