Test a string for upper and lower case?-VBForums
Results 1 to 3 of 3

Thread: Test a string for upper and lower case?

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2011
    Posts
    4

    Test a string for upper and lower case?

    How do you test a string entered by the user via a userform for uppercase? If any uppercase letters are present in the string I want it to return true, it it does not contain lowercase I want it to return false...

    Thanks!
    Last edited by jasminalison; Jan 5th, 2012 at 06:07 AM.

  2. #2
    Addicted Member
    Join Date
    Jan 2009
    Posts
    183

    Re: Test a string for upper and lower case?

    Quote Originally Posted by jasminalison View Post
    How do you test a string entered by the user via a userform for uppercase? If any uppercase letters are present in the string I want it to return true, it it does not contain lowercase I want it to return false...

    Thanks!
    I'm assuming you meant to say "if it does not contain uppercase I want it to return false"

    This should return true if there are any uppercase letters
    Function containsUpperCase(testString As String) As Boolean
    containsUpperCase = (testString <> LCase(testString))
    End Function

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    20,003

    Re: Test a string for upper and lower case?

    if you want to confirm a mix of upper and lower case
    vb Code:
    1. Function casemixed(s As String) As Boolean
    2.     If Not (LCase(s) = s Or UCase(s) = s) Then casemixed = True
    3. End Function
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.