VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Capitalise First Letters

by Pat Dolan (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

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

Assumes
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.

Rate Capitalise First Letters

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

Download this snippet    Add to My Saved Code

Capitalise First Letters Comments

No comments have been posted about Capitalise First Letters. Why not be the first to post a comment about Capitalise First Letters.

Post your comment

Subject:
Message:
0/1000 characters