Results 1 to 8 of 8

Thread: Detect uppercase

  1. #1

    Thread Starter
    Hyperactive Member Sacofjoea's Avatar
    Join Date
    May 2000
    Location
    Never Never Land
    Posts
    472
    How can i detect if the user has an upper-case letter in the textbox when they hit ok?
    That arranged can be

  2. #2
    Guest
    Code:
    Private Sub Command1_Click()
        Dim IsIt As Boolean
        For i = 1 To Len(Text1)
            If Asc(Mid(Text1, i, 1)) = Asc(UCase(Mid(Text1, i, 1))) Then
                IsIt = True
            Else
                IsIt = False
            End If
        Next
        If IsIt = True Then MsgBox "uppercase"
    End Sub
    Text1 cant have numbers or it will say there is UpperCase even if it isnt.

  3. #3
    Use keypress event of the textbox and get the ASCII value of the letter currently entered.
    Madhusudana Gorthi [email protected]
    Senior Software Engineer
    www.stgil.com

  4. #4
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335

    Ascii Value

    I think he meant this:

    Code:
    If KeyAscii = bla then blabla
    Replace bla with the value of the Ascii and blabla with the command you want to give him.

    To view the Ascii Value list go to the Help Topics on VB and see under Character Sets.
    Then go to See Also and go to the other Character Sets to see part 2 of the list.

    I hope I helped.
    Asaf Sagi

    ICQ: 61917199
    E-Mail: [email protected]

  5. #5
    Guest
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
       If Chr(KeyAscii) = UCase(Chr(KeyAscii)) Then MsgBox "Uppercase detected!"
    End Sub
    I hope this helps.


  6. #6
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    You could also use the Like Statement with the "*[A-Z]*" Pattern, i.e.
    Code:
    Private Sub Command1_Click()
        Caption = IIf(Text1 Like "*[A-Z]*", "Contains Uppercase Chars", "No Uppercase Chars.")
    End Sub

  7. #7
    Guest
    I would rather use a Select Case or If...Then, than a IIf statement, it is less code, but I heard IIf is a lot slower than a normal If...Then.

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Thumbs up

    Aaron's example should be fast enough but this could be even faster:
    Code:
    If text1<>lcase(text1) then msgbox "Contains upper case"
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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