VB textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shruthibhat
    New Member
    • Sep 2007
    • 2

    #1

    VB textbox

    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.......
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by shruthibhat
    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.

    Comment

    • QVeen72
      Recognized Expert Top Contributor
      • Oct 2006
      • 1445

      #3
      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
      Veena

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        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

        Working...