Search Tools Links Login

Capitalise First Letters

Takes an input string iof words and changes first letter of each word to a Capital letter

Original Author: Pat Dolan


cut and paste the code into a new project.
clicking the convert button 'capitalises' the words in the first text box to the second text box.


Option Explicit
Private Sub btnConvert_Click()
  Text2.Text = toCapitals(Text1.Text)
End Sub
Private Sub Form_Load()
Text1 = "the cat in the hat works in the c.i.a."
Text2 = ""
End Sub
Function toCapitals(strLowerCase)
  Dim ii, jj
  '--- determine how long the string to be converted is
  ii = Len(strLowerCase)
  '--- first letter of string will always be capitalised
  toCapitals = UCase(Mid(strLowerCase, 1, 1))
  '--- Check the rest of the unconverted string
  '--- We capitalise the next letter whenever we find a space or a break
  For jj = 1 To ii - 1
    If Mid(strLowerCase, jj, 1) = " " Or Mid(strLowerCase, jj, 1) = "." Then
      toCapitals = toCapitals & UCase(Mid(strLowerCase, jj + 1, 1))
      toCapitals = toCapitals & Mid(strLowerCase, jj + 1, 1)
    End If
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 85 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.