Capitalise First Letters
Takes an input string iof words and changes first letter of each word to a Capital letter
Original Author: Pat Dolan
Assumptions
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.
Code
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))
Else
toCapitals = toCapitals & Mid(strLowerCase, jj + 1, 1)
End If
Next
End Function
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.