Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2002
    Posts
    49

    Unanswered: Formatting a string

    Does any one out there know an easy way to format a string. I'm asking for a full name from my user, and want to ensure that it is formatted properly. I would like each of the first letters to be capitalized reqardless of the caps lock status. I came close with the input mask of >L<?????????????????????????..., but as you can see, I can only change the case of the first name entered. I have written a "brute force" code to strip each letter from the string ans check if it's upper or lower case. Using chr(32), I then determine which letters need to be capitalized. using len(strname) I set up a for next loop and slowly peel away at the string (very crude I admit). My other thought was to have seperate for first and last names, but some of the clients will require the use of the full middle name, so that is not an available option. Besides, I'm getting the input form too crowded, so I only want 1 text box. Any help will be greatly appreciated.

    P.S.
    for clarification:

    "john paul franks", "jOhN PaUL frANks"...etc, wil be "John Paul Franks"

  2. #2
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    i don't know about predefined formats but this will do the job from vb i'd recomend in the After Update Event,

    Code:
    Private Sub txtbox_AfterUpdate()
        txtbox = scase(txtbox)
    end sub
    
    
    Function SCase(str As String) As String
        Dim space As Long
        space = InStrRev(str, " ")
        If space = 0 Then
            SCase = UCase(Left$(str, 1)) & LCase(Right(str, Len(str) - 1))
        Else
            SCase = SCase(Left$(str, space - 1)) & " " & UCase(Mid$(str, space + 1, 1)) & _
    LCase(Right(str, Len(str) - space - 1))
        End If
    End Function
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  3. #3
    Join Date
    Nov 2002
    Posts
    49
    I didn't think there was a "canned" format I could use. I'll give this a shot and let you know what happened. Thanks

  4. #4
    Join Date
    Jan 2003
    Location
    Netherlands
    Posts
    10
    Look at the StrConv() function:

    strName = StrConv(strName,3)

    or:

    strName = strConv(strConv(strName,2),3)


    greetings from Holland,
    Henny

  5. #5
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    ahh, i new there was a built in one, but could I find it.
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

Posting Permissions

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