We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,688 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to transfer letter from textbox to label

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

5
Contributors
6
Replies
1 Day
Discussion Span
5 Months Ago
Last Updated
8
Views
glenndr_15
Newbie Poster
16 posts since May 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Hi,

You should look at the Keypress event for the textbox

G_Waddell
Practically a Master Poster
623 posts since Nov 2009
Reputation Points: 107
Solved Threads: 95
Skill Endorsements: 6

Try textbox_TextChangeEvent

Label1.Text=Textbox1.text
poojavb
Posting Pro
524 posts since Nov 2011
Reputation Points: 39
Solved Threads: 77
Skill Endorsements: 7

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

tinstaafl
Nearly a Posting Virtuoso
1,470 posts since Jun 2010
Reputation Points: 421
Solved Threads: 262
Skill Endorsements: 14

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

glenndr_15
Newbie Poster
16 posts since May 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

mr hacker
Light Poster
39 posts since Dec 2012
Reputation Points: -2
Solved Threads: 1
Skill Endorsements: 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
tinstaafl
Nearly a Posting Virtuoso
1,470 posts since Jun 2010
Reputation Points: 421
Solved Threads: 262
Skill Endorsements: 14

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0848 seconds using 2.68MB