Results 1 to 9 of 9

Thread: VB Snippet - Capatalize first Letter in all words in string

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    VB Snippet - Capatalize first Letter in all words in string

    VB Code:
    1. Function UpAllWords(ByVal TEXTIN As String) As String
    2.  
    3. Dim TextinS() As String
    4.  
    5. Dim Letter As String
    6.  
    7. Dim FinalWord As String
    8.  
    9. Dim MyItem As Integer
    10.  
    11. Dim c As Integer
    12.  
    13. TextinS = Split(TEXTIN, " ")
    14.  
    15. MyItem = UBound(TextinS)
    16.  
    17. For c = 0 To MyItem
    18.  
    19.      Letter = Left(TextinS(c), 1)
    20.  
    21.      Letter = UCase(Letter)
    22.  
    23.      FinalWord = (Right(Letter, 1)) & Mid(TextinS(c), 2)
    24.      
    25.      TextinS(c) = FinalWord
    26.  
    27.      If UBound(TextinS) = c Then
    28.          
    29.           UpAllWords = UpAllWords & TextinS(c)
    30.      
    31.      Else
    32.    
    33.           UpAllWords = UpAllWords & TextinS(c) & " "
    34.      
    35.      End If
    36.  
    37. Next c
    38.  
    39. End Function
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  2. #2

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Never get tired of pissing on my parade, huh?
    Yes , you are correct....
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  4. #4
    Fanatic Member
    Join Date
    Jun 2000
    Location
    Forest
    Posts
    545
    Originally posted by MartinLiss
    StrConv("this is a string", vbProperCase)

    Does the same thing I think.
    There are some downside to STRConv.
    MsgBox StrConv("C:\Documents and Settings\All Users", vbProperCase)

    Would return something like this.
    "C:\documents And Settings\all Users"

    I think James method combined with strconv would be the idea choice. I altered your code a little bit James.
    Code:
    Option Explicit
    
    Private Sub Form_Load()
        MsgBox UpAllWords("C:\documents and settings\All users", "\")
    End Sub
    
    Function UpAllWords(ByVal TEXTIN As String, Optional ByVal strDelimiter As String = " ") As String
        Dim TextinS() As String
        
        Dim c As Integer
        
        TextinS = Split(TEXTIN, strDelimiter)
        
        For c = 0 To UBound(TextinS)
             TextinS(c) = StrConv(TextinS(c), vbProperCase)
        Next c
        
        UpAllWords = Join(TextinS, strDelimiter)
    End Function
    Bird of Prey

    Mr. Bald Eagle.
    [img][/img]

  5. #5
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    This all sounds very familiar to me.
    The code samples are getting repeated.
    http://www.vbforums.com/showthread.p...hreadid=231506
    Frans

  6. #6
    Fanatic Member
    Join Date
    Jun 2000
    Location
    Forest
    Posts
    545
    Don't know where James got his original code but my code was trying to enhance his code. As for strConv, I learned years ago and I don't think that is knew to anyone.

    The way you did it in the other thread still would not take care something like this

    "C:\documents and settings\All users"
    Last edited by Hawk; Feb 27th, 2003 at 07:58 PM.
    Bird of Prey

    Mr. Bald Eagle.
    [img][/img]

  7. #7
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    I think this technique is know as "camel writing", because its like a camels hump. Starts high (Ucase) then goes low(Lcase).

    Or was it called "donkey writing"?

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Originally posted by Madboy
    I think this technique is know as "camel writing", because its like a camels hump. Starts high (Ucase) then goes low(Lcase).

    Or was it called "donkey writing"?
    How does your post contribute to this thread?

  9. #9
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    It doesnt as such, but in one of my VB books it mentions this. And i though it would be useful to some, if they need to search such a thing

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