By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

VB textbox

P: 2
how can i count the number of characters,special symbols and numbers given in an input testbox ?eg: if i give the input as i"know12,vb , the output should be as 7 characters,2 special symbols and 2 numbers.......
Sep 2 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 5K+
P: 8,434
how can i count the number of characters ...
What version of VB are you using?

By the way, please don't post questions in the Articles area. I've moved this back to the Visual Basic Forum, where it belongs.
Sep 3 '07 #2

QVeen72
Expert 100+
P: 1,445
Hi,

Parse the Entire String, in a Loop, Keep a Variable for each.. and Count. I will Give you how to count Numbers , you can Modify the code for Chars/Special Chars etc..:

Expand|Select|Wrap|Line Numbers
  1. Dim TNum As Integer
  2. Dim i As Integer
  3. Dim TStr As String * 1 
  4. TNum = 0
  5. For i = 1 To Len(Text1.Text)
  6.    TStr = Mid(Text1.Text, i, 1)
  7.    If InStr("0123456789",TStr) > 0 Then
  8.         TNum = TNum + 1
  9.    End If
  10. Next
  11. MsgBox "Count of Numeric Chars : " & TNum
  12.  
REgards
Veena
Sep 3 '07 #3

Expert 5K+
P: 8,434
I'd suggest creating a function which returns the "type" of a given character. That way, you can do things like...
Expand|Select|Wrap|Line Numbers
  1. Dim I As Long ' <-- If later than VB6, use Integer.
  2. Dim strChar As String * 1 
  3. For I = 1 To Len(Text1.Text)
  4.   strChar = Mid(Text1.Text, I, 1)
  5.   Select Case CharType(strChar)
  6.     Case "A" ' Alpha
  7.       ' Increment your count of letters
  8.     Case "N" ' Numeric
  9.       ' Increment your count of numeric digits
  10.     Case "P" ' Punctuation
  11.       ' Increment your count of punctuation symbols
  12.     Case "S" ' Special character
  13.       ' Increment your count of 'special' symbols
  14.   End Select
  15. Next
Sep 4 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.