LCase and UCase Functions
The LCase function converts a string to lower case. The UCase function converts a string to upper case.
Syntax
UCase(string)
string is a string variable or text inside quotes.
Look at the following example.
Example 1 |
Dim strText As String strText = "Miami" lblCity.Caption = UCase(strText) |
What is the result of Example 1?
StrConv Function
The StrConv function converts a string to lower, upper, or title case (first letter of each word is capitalized).
Syntax
string is a string variable or text inside quotes. conversion can be
vbUpperCase
, vbLowerCase
, or vbProperCase
(for title case).
Look at the following example.
Example 2 |
Dim strText As String strText = "chicago bears" lblTeam.Caption = StrConv(strText, vbProperCase) |
What is the result of Example 2?
Class Exercise: Text Case
We’re going to create program to change the case of a string.
- Begin by designing the form.
- Use the names
txtInput, optUpper, optLower, optTitle, lblOutput, cmdDone
for the controls on the form. - Add code to
cmdDone
. - Add the code for
optUpper
,optLower
, andoptTitle
.
Text Case Code |
Private Sub cmdDone_Click() ' end program Unload frmMain End Sub Private Sub optUpper_Click() Private Sub optLower_Click() Private Sub optTitle_Click() |
Class Assignment: Text Case 2.0
Modify your program so that as the input changes, the output is updated.
- Create a subroutine called
ConvertCase()
. - Make the click event for the option buttons call
ConvertCase()
. - Try your program out to make sure it works.
- Raise your hand and ask your teacher to grade your assignment on screen.