-
October 17th, 2013, 07:35 PM
#1
Visual Basic Coding Help: Last Name Won't Capitalize
The program I'm working on allows the user to enter names (first, middle, and last names, like "First Middle Last") into a list box in the correct case. I have two problems so far when I use the debug command. The last name won't capitalize and the middle name reappears after the last name, except the first letter is removed and the letter after that is capitalized. I could use a little help figuring this out.
The rest of the code seems to be working, it's just the name part, but I've uploaded the full code just in case there was an error I missed.
In case it makes any difference, I'm using Microsoft Visual Basic 2010 Express.
Code:
Option Explicit On
Option Strict On
Option Infer Off
Public Class MainForm
Private Sub nameTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles nameTextBox.Enter
' select the existing text
nameTextBox.SelectAll()
End Sub
Private Sub fileExitMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles fileExitMenuItem.Click
Me.Close()
End Sub
Private Sub filePrintMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles filePrintMenuItem.Click
PrintForm1.PrintAction =
Printing.PrintAction.PrintToPreview
PrintForm1.Print()
End Sub
Private Sub addButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles addButton.Click
Dim fullName As String
Dim firstName As String
Dim middleName As String
Dim lastName As String
Dim index As Integer
fullName = nameTextBox.Text.Trim
If fullName = String.Empty Then
MessageBox.Show("Please enter a name",
"Bucky Burgers",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
index = fullName.IndexOf(" ")
If index > -1 Then
firstName = fullName.Substring(0, index)
middleName = fullName.Substring(index + 1)
lastName = fullName.Substring(index + 2)
firstName =
firstName.Substring(0, 1).ToUpper &
firstName.Substring(1).ToLower
middleName =
middleName.Substring(0, 1).ToUpper &
middleName.Substring(1).ToLower
lastName =
lastName.Substring(0, 1).ToUpper &
lastName.Substring(1).ToLower
fullName = firstName & " " & middleName & " " & lastName
Else
fullName =
fullName.Substring(0, 1).ToUpper &
fullName.Substring(1).ToLower
End If
namesListBox.Items.Add(fullName)
End If
nameTextBox.Focus()
nameTextBox.SelectAll()
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|