1,105,450 Community Members

How to transfer letter from textbox to label

Member Avatar
glenndr_15
Newbie Poster
16 posts since May 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
G_Waddell
Practically a Posting Shark
821 posts since Nov 2009
Reputation Points: 131 [?]
Q&As Helped to Solve: 137 [?]
Skill Endorsements: 13 [?]
 
0
 

Hi,

You should look at the Keypress event for the textbox

Member Avatar
poojavb
Posting Pro
524 posts since Nov 2011
Reputation Points: 29 [?]
Q&As Helped to Solve: 78 [?]
Skill Endorsements: 9 [?]
 
1
 

Try textbox_TextChangeEvent

Label1.Text=Textbox1.text
Member Avatar
tinstaafl
Postaholic
2,012 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 403 [?]
Skill Endorsements: 36 [?]
 
0
 

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

Member Avatar
glenndr_15
Newbie Poster
16 posts since May 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Mr.M
Junior Poster
197 posts since Dec 2012
Reputation Points: -2 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 2 [?]
 
0
 

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

Member Avatar
tinstaafl
Postaholic
2,012 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 403 [?]
Skill Endorsements: 36 [?]
 
0
 

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
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: