hey guys. i've got this code where i've gotta separate a full name and tell the user which is which (meaning "this name is first, this name is middle, and this is your last name" type stuff). Well i've got the first part working where the program tells you what part of the name you're using but i've also got to tell the user this:

Short length names are defined as 6 or fewer letters.

Standard length names are defined as 7 to 10 letters.

Long length names are defined as having more than 11 letters.

this meaning i've got to say: "your first name is Michael, it has 7 letters, it is standard length. your middle name is john, it has 4 letters, it is short length. your last name is kirkpatrick, it has 11 letters, it is long length."

help? here's the code

Private Sub xCalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xCalcButton.Click
        'go for it!
        Dim i As Integer

        Dim wholename As String
        Dim namepart(3) As String

        wholename = Me.xEnterTextBox.Text

        For i = 0 To Me.xEnterTextBox.Text.Length - 1
            namepart = wholename.Split(" ")
        Next

        Me.xAnswerLabel.Text = "Your first name is " & namepart(0) & ". " & _
            "Your middle name is " & namepart(1) & ". " & "Your last name is " & namepart(2) & ". "

    End Sub

Thanx in advance for any help to get me over the hump

great news! i've figured it all down to 1 thing... the last word is not displaying the length correctly... any help, my logic's gotta be wrong at the last piece of the message in the label

Private Sub xCalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xCalcButton.Click
        'go for it!
        Dim i As Integer
        Dim textlength As Integer
        Dim textlength1 As Integer
        Dim textlength2 As Integer

        Dim wholename As String
        Dim namepart(3) As String
        Dim length(3) As String

        wholename = Me.xEnterTextBox.Text

        For i = 0 To Me.xEnterTextBox.Text.Length - 1
            namepart = wholename.Split(" ")
        Next

        textlength = namepart(0).Length

        If textlength <= 6 Then
            length(0) = "short"
        ElseIf textlength > 6 And textlength <= 10 Then
            length(0) = "standard"
        ElseIf textlength >= 11 Then
            length(0) = "long"
        End If

        textlength1 = namepart(1).Length

        If textlength1 <= 6 Then
            length(1) = "short"
        ElseIf textlength1 > 6 And textlength <= 10 Then
            length(1) = "standard"
        ElseIf textlength1 >= 11 Then
            length(1) = "long"
        End If

        textlength2 = namepart(2).Length

        If textlength2 <= 6 Then
            length(2) = "short"
        ElseIf textlength2 > 6 And textlength <= 10 Then
            length(2) = "standard"
        ElseIf textlength2 >= 11 Then
            length(2) = "long"
        End If

        Me.xAnswerLabel.Text = "Your first name is " & namepart(0) & ", it is " & textlength & _
            " characters," & " and it is " & length(0) & " length" & ". " & _
            "Your middle name is " & namepart(1) & ", it is " & textlength1 & _
            " characters," & " and it is " & length(1) & " length" & ". " & _
            "Your last name is " & namepart(2) & ", it is " & textlength2 & _
            " characters," & " and it is " & length(2) & " length" & ". "

    End Sub

Try this:

Private Sub xCalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xCalcButton.Click
        'go for it!
        Dim gLoop As Long

        Dim namepart(3) As String
        Dim length(3) As String

        namepart = TextBox1.Text.Split(" ")

        For gLoop = 0 To 2
            If Len(namepart(gLoop)) <= 6 Then
                length(gLoop) = "short"
            ElseIf Len(namepart(gLoop)) <= 6 And Len(namepart(gLoop)) <= 10 Then
                length(gLoop) = "standard"
            ElseIf Len(namepart(gLoop)) >= 11 Then
                length(gLoop) = "long"
            End If
        Next

        Me.xAnswerLabel.Text = "Your first name is " & namepart(0) & ", it is " & Len(namepart(0)) & _
            " characters," & " and it is " & length(0) & " in length" & ". " & _
            "Your middle name is " & namepart(1) & ", it is " & Len(namepart(1)) & _
            " characters," & " and it is " & length(1) & " in length" & ". " & _
            "Your last name is " & namepart(2) & ", it is " & Len(namepart(2)) & _
            " characters," & " and it is " & length(2) & " in length" & ". "

    End Sub

thanx. now it's weird b/c it won't work if the length is standard. like if the length is standard, nothing shows in the blank i've set for it

i know this seems like the dumbest thing on the planet but this works:

If textlength2 > 10 Then
            length(2) = "long"
        ElseIf textlength2 > 6 And textlength <= 10 Then
            length(2) = "standard"
        ElseIf textlength2 <= 6 Then
            length(2) = "short"
        End If

and this one doesn't

If textlength2 <= 6 Then
            length(2) = "short"
        ElseIf textlength2 > 6 And textlength <= 10 Then
            length(2) = "standard"
        ElseIf textlength2 > 10 Then
            length(2) = "long"
        End If

go figure...and it's only on this structure. the others never had that problem

finally got it!

this works. don't ask me what made this code any better than what was originally down but whatever

textlength = namepart(0).Length

        If textlength <= 6 Then
            length(0) = "short"
        ElseIf textlength > 10 Then
            length(0) = "long"
        Else
            length(0) = "standard"
        End If

        textlength1 = namepart(1).Length

        If textlength1 <= 6 Then
            length(1) = "short"
        ElseIf textlength1 > 10 Then
            length(1) = "long"
        Else
            length(1) = "standard"
        End If

        textlength2 = namepart(2).Length

        If textlength2 > 10 Then
            length(2) = "long"
        ElseIf textlength2 <= 6 Then
            length(2) = "short"
        Else
            length(2) = "standard"
        End If

I'm not sure what you mean. Please could you explain a bit further?

well i changed this:

If textlength2 <= 6 Then
            length(2) = "short"
        ElseIf textlength2 > 6 And textlength <= 10 Then
            length(2) = "standard"
        ElseIf textlength2 > 10 Then
            length(2) = "long"
        End If

to this:

If textlength2 > 10 Then
            length(2) = "long"
        ElseIf textlength2 <= 6 Then
            length(2) = "short"
        Else
            length(2) = "standard"
        End If

and now it works just fine

Just for interest, your problem was here:

ElseIf textlength2 > 6 And textlength <= 10 Then

Probably should be textlength2

well i changed this:

If textlength2 <= 6 Then
            length(2) = "short"
        ElseIf textlength2 > 6 And textlength <= 10 Then
            length(2) = "standard"
        ElseIf textlength2 > 10 Then
            length(2) = "long"
        End If

to this:

If textlength2 > 10 Then
            length(2) = "long"
        ElseIf textlength2 <= 6 Then
            length(2) = "short"
        Else
            length(2) = "standard"
        End If

and now it works just fine

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.