Hello all.
I am trying to to get a label to display a reformatted name, but no matter what I put in the text box it always reads "Name New." Those exact words.
What am I doing wrong?
Public Class Form1
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNewName.Click
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim StrNewName As String = txtNewName.Text.Trim
Call AddName(StrNewName)
I am trying to to get a label to display a reformatted name, but no matter what I put in the text box it always reads "Name New." Those exact words.
What am I doing wrong?
Public Class Form1
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNewName.Click
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim StrNewName As String = txtNewName.Text.Trim
Call AddName(StrNewName)
Code:
End Sub
Private Function AddName(ByVal strNewName As String) As String
strNewName = txtNewName.Text
Dim IntSpace As Integer = strNewName.IndexOf(" ")
Dim IntLength As Integer = strNewName.Length
IntLength = IntLength - 3
If IntSpace <> -1 Then
Dim StrFirstName As String = strNewName.Substring(0, IntSpace)
Dim StrLastName As String = strNewName.Substring(IntSpace + 1)
strNewName = StrLastName & " " & StrFirstName
lblName.Text = strNewName
Else
MessageBox.Show("Please enter a first name followed by a second name, seperated with a space.")
End If
End Function
End Class