Advertisement
2002VB Miscellaneous #19158

Capitalise First Letters

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

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
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
Original Comments (3)
Recovered from Wayback Machine