Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this exercise, you modify the Proper Case application from Exercise 6. If necessary, complete Exercise 6. Then, use Windows to make a copy of

In this exercise, you modify the Proper Case application from Exercise 6. If necessary, complete Exercise 6. Then, use Windows to make a copy of the Proper Case Solution folder. Rename the copy Proper Case Solution-Middle. Open the Proper Case Solution.sln file contained in the Proper Case Solution-Middle folder. Modify the application to allow the user to also enter his or her middle name or middle initial. The btnProper_Click procedure should display the full name, which might include a middle name or middle initial, in proper case. Save the solution and then start and test the application. (If the user enters john smith as the name, the application should display John Smith. If the user enters john thomas smith, the application should display John Thomas Smith. If the user enters carol g. jones, the application should display Carol G. Jones. If the user enters two spaces, pam, two spaces, grace, three spaces, darwin, and two spaces, the application should display Pam Grace Darwin.)

See Code below:

frmMain.vb

Option Explicit On Option Strict On Option Infer Off

Public Class frmMain

Private Sub btnProper_Click(sender As Object, e As EventArgs) Handles btnProper.Click Dim strName As String Dim strFirstName As String Dim strLastName As String Dim intIndex As Integer Dim intLastIndex As Integer

strName = txtName.Text.Trim()

'display error if the user didnot enter any name If strName = "" Then MessageBox.Show("Enter a First and Last name", "Proper Case", MessageBoxButtons.OK, MessageBoxIcon.Information) Else 'get the index of first space intIndex = strName.IndexOf(" ") 'get the index of last space intLastIndex = strName.LastIndexOf(" ") 'if there are no spaces in the string, convert and display name in proper case If intIndex = -1 Then strFirstName = strName.Substring(0, 1).ToUpper & strName.Substring(1).ToLower lblName.Text = strFirstName Else 'if the first and last index of space is equal, it means there is only one space If intIndex = intLastIndex Then 'convert and display the name in proper case strFirstName = strName.Substring(0, intIndex) strLastName = strName.Substring(intIndex + 1) strFirstName = strFirstName.Substring(0, 1).ToUpper & strFirstName.Substring(1).ToLower strLastName = strLastName.Substring(0, 1).ToUpper & strLastName.Substring(1).ToLower lblName.Text = strFirstName & " " & strLastName Else 'if there are multiple spaces, get the first name and trim it strFirstName = strName.Substring(0, intLastIndex) strFirstName = strFirstName.Trim() strLastName = strName.Substring(intLastIndex + 1) 'convert and display the name in proper case strFirstName = strFirstName.Substring(0, 1).ToUpper & strFirstName.Substring(1).ToLower strLastName = strLastName.Substring(0, 1).ToUpper & strLastName.Substring(1).ToLower lblName.Text = strFirstName & " " & strLastName End If End If End If txtName.Focus() End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Me.Close() End Sub

Private Sub txtName_Enter(sender As Object, e As EventArgs) Handles txtName.Enter txtName.SelectAll() End Sub

Private Sub txtName_TextChanged(sender As Object, e As EventArgs) Handles txtName.TextChanged lblName.Text = String.Empty End Sub

End Class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions