Im trying to Separate First Name, Middle Initial, and last name into Textboxes, with a function of a button.

Example :

Full Name : Tony J Holley

First Name: Tony
Middle Initial: J
Last Name: Holley

All I have is this, and is for the first name Separator:

' determines the person's first name
Dim name As String
name = txtfullname.Text
txtfirstname.Text = firstname(name)

End Sub
Function firstname(ByVal name As String) As String
Dim firstspace As Integer
firstspace = name.IndexOf(" ")
Return name.Substring(0, firstspace)


I don't know how to separate the middle Initial nor the Last name.


Thanks In Advance.

Member Avatar for iamthwee

>Tony J Holley

Does your name have three words in it always. Is each word separated by only one space. Please answer these questions.

Yeah Three names and Yes only one space between names.

you can use split method in string class

Dim namepart(3) As String
         fullname = TextBox1.Text

        For i = 0 To TextBox1.Text.Length - 1
            namepart = fullname.Split(" ")
        Next
        TextBox2.Text = namepart(0)
        TextBox3.Text = namepart(1)
        TextBox4.Text = namepart(2)

you can read more about array here and about string here

It keeps telling me "i" is not declared ?

blah I got it, Thanks Manal :), me without this site :P. THANKS AGAIN.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.