Important alert: (current site time 10/31/2014 8:24:17 AM EDT)
 

VB icon

[ A program to count the number of characters in a TextBox. ]

Email
Submitted on: 8/6/2003 6:10:52 AM
By: JamesJD  
Level: Beginner
User Rating: By 8 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 15127
author picture
(About the author)
 
     This simple little program will count the number of characters in a TextBox. Please leave your comments and votes, thanks :)

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: [ A program to count the number of characters in a TextBox. ]
' Description:This simple little program will count the number of characters in a TextBox. Please leave your comments and votes, thanks :)
' By: JamesJD
'
' Inputs:One TextBox, one Label, and two CommandButtons. (You just need to keep their default names).
'
' Returns:The number of characters entered into the TextBox.
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=47446&lngWId=1'for details.'**************************************

Sub Clear()
Text1.Text = ""
Label1.Caption = "Characters: "
Text1.SetFocus
End Sub
Private Sub Command1_Click()
Label1.Caption = "Characters: " & Str$(Len(Text1.Text))
Text1.SetFocus
End Sub
Private Sub Command2_Click()
Call Clear
End Sub


Other 21 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

8/6/2003 9:32:41 AMDaniel K Murphy

I guess that is a quick way to do it! Thanks for posting!
(If this comment was disrespectful, please report it.)

 
8/7/2003 8:01:48 AM

length = Len(Textbox) ?
(If this comment was disrespectful, please report it.)

 
8/7/2003 12:11:05 PMNate Bross

Command1_Click ()
MsgBox Len(Text1.text)
End Sub
(If this comment was disrespectful, please report it.)

 
8/8/2003 6:24:16 AMJames Shanelec

that counts everything, spaces and all, not just charactors, u oughtta change its name to "kinda counts chactors in a textbox" well, either that or just remove this horrible code...
(If this comment was disrespectful, please report it.)

 
8/30/2003 11:34:03 AMJeroen van de Ven

try this to remove spaces:

'---start
TxtWOSpaces = split(Text, " ")
For X = 0 to ubound(TxtWOSpaces)
TxtWOSpaces2 = txtwospaces(X)
Next X
LengthWOSpaces = len(TxtWOSpaces2)
'---end

(If this comment was disrespectful, please report it.)

 
8/30/2003 11:40:11 AMJeroen van de Ven

Sorry, this is the right code:

txtwospaces = Split(Text1.Text, " ")
For X = 0 To UBound(txtwospaces)
txtwospaces2 = txtwospaces2 & txtwospaces(X)
Next X
LenWO = Len(txtwospaces2)
LenW = Len(Text1.Text)
(If this comment was disrespectful, please report it.)

 
9/29/2003 12:51:26 AMKalyana Kumar

Excellent piece of work JamesJD.My vote is for you.Keep up the good work.Well
deserved 5 globe from me.Thanks for sharing.
(If this comment was disrespectful, please report it.)

 
11/13/2003 10:42:26 PM

ok this is pointless
(If this comment was disrespectful, please report it.)

 
11/20/2003 8:40:32 PMNick Oz

i honestly dont know why you would even post this
(If this comment was disrespectful, please report it.)

 
6/29/2004 1:24:25 PMrainmanp7

Somtimes I like posts like this because it gets the people to give the real information or other ideas

Thank you for posting this :)
(If this comment was disrespectful, please report it.)

 
8/3/2004 8:23:09 AM

"Private Sub Command2_Click()
Call Clear
End Sub"
=>
Private Sub Command2_Click()
Clear
End Sub
(If this comment was disrespectful, please report it.)

 
8/6/2004 11:31:29 AM

What about the multi-line textboxes? You see, if you have more then 1 line in your textbox, crlf chars are added in the end of each line...
(If this comment was disrespectful, please report it.)

 
8/16/2004 12:04:02 PMKristian.S.Stangeland

Here's an easier way to count all characters in a string except spaces:

Length = Len(Replace(Text1.Text,
(If this comment was disrespectful, please report it.)

 
8/31/2004 4:52:29 PM

I was looking for something like this and I appreciate it. I needed to be able to count blank spaces, tabs, & special characters.
(If this comment was disrespectful, please report it.)

 
3/27/2005 10:30:04 AMHardStream Software Development

Only App.TaskVisible=False is worse than this code...
(If this comment was disrespectful, please report it.)

 
1/2/2007 3:40:45 PMDR

I give you 5 globes it is great. WORKS great in my data base text box, where the limit is 5000. They do not have to count it all. Thanks a million.
(If this comment was disrespectful, please report it.)

 
1/22/2010 1:20:17 AMagebp

this cool, thanks
(If this comment was disrespectful, please report it.)

 
3/30/2010 4:10:50 PMlittle_master

regex pattern is best for counting those

Dim ResultString As String
Dim myMatches As MatchCollection
Dim myRegExp As RegExp
Set myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.Pattern = "(\w|\W|\d)"
Set myMatches = myRegExp.Execute(SubjectString)
Msgbox myMatches.Count
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.