Greetings!
I just want to ask on how to transfer a letter from a textbox to label? what I mean is for example we have a label then a textbox, In a textbox I'm going to type a random words/letters then If there is a letter "A" in the text box it will be automatically transfered to label. Is someone knows the code? any Idea? thanks in advance.

Best regards,
glenndr_15

Recommended Answers

All 6 Replies

Try textbox_TextChangeEvent

Label1.Text=Textbox1.text

Try this:

    Public Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Dim KeyChr As Char = e.KeyChar
        If KeyChr.ToString.ToUpper = "A" Then
            Label1.Text += KeyChr.ToString
        End If
    End Sub

Anytime an a or an A is entered in the textbox it gets echoed to the label.
If you don't want it echoed, and want it removed from the textbox, inside the if block, just add this e.Handled = True

How about if I want to transfer a letter at a certain column?

well for that you will have to do as tinsaafl says but you will change the Label1.Text to that column you want.

I assume when you say column you mean the index of a letter in a string. To remove a letter from a string you can use the Remove method. You probable want to use a button to do this:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Indx As Integer = 0
        Dim NewString As String = TextBox1.Text
        Indx = NewString.ToUpper.IndexOf("A")
        If Not (Indx = 0) Then
            Label1.Text += NewString.Substring(Indx, 1)
            TextBox1.Text = NewString.Remove(Indx, 1)
        End If
    End Sub

Instead of using a literal string("A") you can use any character or string variable, also instead of using the index of a particular letter you can just use any number that corresponds to a particular position in the string regardless of letter.

You can include functionality to use the Enter key like this:

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = ChrW(Keys.Return) Then
            Button1.PerformClick()
            e.Handled = True
        End If
    End Sub
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.