Hi everyone! I have an assign ment that says: create an application to let the user enter his or her name (first and last name), then displays the Initial in Upper Case. FOr example: you enter "John Wow", then the Label will display "JW".

I know that I'm supposed to use the Substring method. But to use the Substring, I have to have the exact location of the Leter that is going to be displayed in the Label.

The problem is: the name that the user enters always vary. So in strnewstring.Substring(... , ...) ---> the number in the parenthesis would vary, too. Thus, I cannot put a number in there.

So how can i create a code for this particular assignment.Please help me. Thank you for your time!

Recommended Answers

All 4 Replies

Dim words() As String
        words = Split(TextBox3.Text, " ")
        Label4.Text = UCase$(words(1).Substring(1, 1)) & UCase$(words(2).Substring(1, 1))

You may like to enhance it to cope with more than two words by enclosing it in a loop

for i = 0 to ubound(words)


next i

I try your first code, but it said "Index was out of range of Arry"
And it never works.
May you revise it a little bit please?
I really need to understand this assignment.
Thank you

This goes into a messagebox, but could go into an label. Create a form with a textbox and a button. Enter a name into the form (must be more than one name, or you will get an array error). Click the button and get the messagebox.

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
Dim wholeName As String
        Dim name As String()
        Dim firstInitial As String
        Dim secondInitial As String

        wholeName = TextBox1.Text
        name = Strings.Split(wholeName)
        firstInitial = Strings.Left(name(0), 1)
        secondInitial = Strings.Left(name(1), 1)

        MsgBox(firstInitial & secondInitial)
    End Sub

End Class

I try your first code, but it said "Index was out of range of Arry"
And it never works.
May you revise it a little bit please?
I really need to understand this assignment.
Thank you

sorry about that should arrays start at 0 not 1

words = Split(TextBox3.Text, " ")
        Label4.Text = UCase$(words(0).Substring(0, 1)) & UCase$(words(1).Substring(0, 1))
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.