how can i count the number of characters,spec ial 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.......
VB textbox
Collapse
X
-
Tags: None
-
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..:
[code=vb]
Dim TNum As Integer
Dim i As Integer
Dim TStr As String * 1
TNum = 0
For i = 1 To Len(Text1.Text)
TStr = Mid(Text1.Text, i, 1)
If InStr("01234567 89",TStr) > 0 Then
TNum = TNum + 1
End If
Next
MsgBox "Count of Numeric Chars : " & TNum
[/code]
REgards
VeenaComment
-
I'd suggest creating a function which returns the "type" of a given character. That way, you can do things like...
[CODE=vb]Dim I As Long ' <-- If later than VB6, use Integer.
Dim strChar As String * 1
For I = 1 To Len(Text1.Text)
strChar = Mid(Text1.Text, I, 1)
Select Case CharType(strCha r)
Case "A" ' Alpha
' Increment your count of letters
Case "N" ' Numeric
' Increment your count of numeric digits
Case "P" ' Punctuation
' Increment your count of punctuation symbols
Case "S" ' Special character
' Increment your count of 'special' symbols
End Select
Next[/CODE]Comment
Comment