Results 1 to 12 of 12

Thread: [RESOLVED] Check textbox contains capital letter

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] Check textbox contains capital letter

    I would like to know how to check the string input by the user?If the user input capclock letter, the the messagebox pop up when i click the command button. I would like to pop up the with mesagebox when the user input the caplock letter "B B" or "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

  2. #2
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: Check textbox contains capital letter

    vb Code:
    1. Dim ValidStr As String
    2.  
    3. Private Sub Form_Load()
    4.     ValidStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    5. End Sub
    6.  
    7. Private Sub Text1_KeyPress( _
    8.     KeyAscii As Integer _
    9. )
    10.     If InStr(ValidStr, ChrW(KeyAscii)) > 0 Then
    11.         MsgBox "Hello"
    12.     End If
    13. End Sub

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Check textbox contains capital letter

    Thank you. it work when user input. If prefer to check the code when use press the commad button. But how to check code?

    Code:
    Private Sub Command1_Click()
    
    ValidStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        If InStr(ValidStr, ChrW(KeyAscii)) > 0 Then
            MsgBox "Hello"
        End If
    End Sub

  4. #4
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Check textbox contains capital letter

    Checking if a string contains capitals is easy...
    Code:
    If Text1.Text <> LCase$(Text1.Text) Then 'the textbox contains capitals
    Depending on the situation it might be better to control the input to the Textbox so that it's always a particular case.

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Check textbox contains capital letter

    Then check validstr against textbox.etxt instead of chrw(keyascii)

  6. #6
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: Check textbox contains capital letter

    vb Code:
    1. Dim ValidStr As String
    2.  
    3. Private Sub Form_Load()
    4.     ValidStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    5. End Sub
    6.  
    7. Private Sub Command1_Click()
    8.     Dim i As Integer
    9.     Dim hasCaps As Boolean
    10.    
    11.     For i = 1 To Len(Text1.Text)
    12.         If InStr(ValidStr, Mid$(Text1.Text, i, 1)) > 0 Then
    13.             hasCaps = True
    14.             Exit For
    15.         End If
    16.     Next
    17.    
    18.     If hasCaps Then
    19.         MsgBox "Textbox contains capital letters."
    20.     End If
    21. End Sub

  7. #7
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Check textbox contains capital letter

    You can leave the
    Code:
    Private Sub Form_Load()
        ValidStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    End Sub
    in the Form_Load and use those changes in your Comand1_Click:
    Code:
    Private Sub Command1_Click()
    Dim i As Integer
    Dim Check As String
    For i = 1 To Len (ValidStr)
       Check = Mid (ValidStr, i,1)
       If InStr(ValidStr, Check) > 0 Then
          MsgBox "Hello"
          Exit Sub
       End If
    Next i
    End Sub
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  8. #8
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: [RESOLVED] Check textbox contains capital letter

    Code:
    Private Sub Command1_Click()
        If Text1.Text = UCase(Text1.Text) And Text1.Text Like "*[A-Z]*" Then
            MsgBox "All letters are Uppercase"
        ElseIf Text1.Text = LCase(Text1.Text) And Text1.Text Like "*[a-z]*" Then
            MsgBox "All letters are Lowercase"
        ElseIf Text1.Text Like "*[A-Za-z]*" Then
            MsgBox "Letters are mixed Uppercase and Lowercase"
        Else
            MsgBox "No letter exist"
        End If
    End Sub
    Last edited by anhn; Apr 28th, 2008 at 05:27 AM.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  9. #9
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: [RESOLVED] Check textbox contains capital letter

    Whats wrong with my one liner? It accounts for the full set of capitals which would include "&#192;&#193;&#194;&#195;&#196;&#197;&#198;&#199;&#200;&#201;&#202;&#203;&#204;&#205;&#206;&#207;&#2 08;&#209;&#210;&#211;&#212;&#213;&#214;&#217;&#218;&#219;&#220;&#221;" in the UK.

  10. #10
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: [RESOLVED] Check textbox contains capital letter

    Quote Originally Posted by Milk
    Whats wrong with my one liner? It accounts for the full set of capitals which would include "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝ" in the UK.
    That is pretty good and should be the first choice for matrik02

  11. #11
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: [RESOLVED] Check textbox contains capital letter

    @matrik02,
    If someone has helped you here or you find a solution yourself then you should say something instead of quietly mark the thread as resolved and go away.
    You still have many other questions you want to have answers.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: [RESOLVED] Check textbox contains capital letter

    Thank you to all of you.

    I used thread number #4 and #2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width