0

Hi! I am trying to do this project for my Comp Prog class. The Project assignment is "Create an application that prompts the user to enter his/her and last name in a single text box. The program returns the user initials in uppercase".

This is what i have. I am using listboxes for now instead to display the initial.

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Name, F, Last As String
        Dim Cnt As Integer = 0
        Name = TextBox1.Text
        Last = Name.Chars(cnt)
        For Cnt = 0 To (Name.Length) - 1
            Last = Name.Chars(Cnt)
            If Last = " " Then
                Cnt = cnt + 1
            End If
        Next
        F = Name.Chars(0)     
        listbox1.items.add(F.ToString.ToUpper & Last.ToString.ToUpper)


    End Sub
End Class

Alright so basically i created variables Names, Last, and F. And Cnt for a counter that equals 0. Set Name to textbox1.text, which i will enter the name. And Last is equal to Name.Chars(Cnt) (So last is queal to textbox1 (name) and character cnt, which is 0. Then i created a for next loop, to which Cnt = 0 to the length of the name. - 1 because ... EX) TOM JONES, is 0,1,2,3,4,5,6,7,8. The Length is of TOM JONES is 9(w/o the 0), so you have to subtract - 1. OK, so i set up a If, then. If Last = " " (BLANK) then the counter = counter + 1... So F is then equal to Char 0, which is the first letter of the name, and add everything to a listbox..

So if i put in a name, Tom Jones for example, it shows TS, The last and first letter, EX) Bob Jones, will display BS.. When it is supposed to be BJ.

Can anyone help me? I been trying to this for the past couple of hours and have no idea what im doing wrong.

Can someone please Help

5
Contributors
6
Replies
22
Views
2 Years
Discussion Span
Last Post by Reverend Jim
0

My teacher is only letting us use For Next Loops. Anything else is not allowed :(

0

Start by taking the string from the textbox and adding a blank at the front. Then scan through the entire string and check each character. If a character is non-blank and is preceded by a blank then add that character (upper case) to your output string. Once you have finished the loop your output string will be the initials

0

The easiest way to do this would be the string.split method.

That would be easier. I assumed because SubString was out that Split would also be disallowed. As for last names with two (or more) words, my last name has two words and I use both first letters in my initials. I can not see any way of determining whether a name like "Mario Van Peebles" consists of two given names plus a surname or one given name and a compound surname.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.