Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27513

Problem Manipulating Strings

$
0
0
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)

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


Viewing all articles
Browse latest Browse all 27513

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>