Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my code

VB
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Label1.Text = TextBox1.Text
    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
        Label2.Text = TextBox2.Text
    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
        Label3.Text = TextBox3.Text
    End Sub

    Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
        Label4.Text = TextBox4.Text
    End Sub

    Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
        Label5.Text = TextBox5.Text
    End Sub

    Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged
        Label6.Text = TextBox6.Text
    End Sub

    Private Sub TextBox7_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox7.TextChanged
        Label7.Text = TextBox7.Text
    End Sub

    Private Sub TextBox8_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox8.TextChanged
        Label8.Text = TextBox8.Text
    End Sub

    Private Sub TextBox9_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox9.TextChanged
        Label9.Text = TextBox9.Text
    End Sub

    Private Sub TextBox10_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox10.TextChanged
        Label10.Text = TextBox10.Text
    End Sub


Is there an easier, less clumsy way of doing this?
Posted
Updated 8-Jun-22 14:07pm

VB
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged,TextBox2.TextChanged,TextBox3.TextChanged,TextBox4.TextChanged 'Do same for all ten textboxes...
    Dim txt as new TextBox
    txt = DirectCast(sender,TextBox)
    Dim No as string = txt.Name.ToString().Replace("TextBox","") 'No will contain 1,2,3...
    DirectCast (Me.Controls.Find("Label" & No,True).GetValue(0),Label).Text = txt.Text    ' this is similar to Label1.Text = TextBox1.Text, Label2.Text = TextBox2.Text...
End Sub

Happy Coding!
:)
 
Share this answer
 
v3
Comments
Davey85 4-Apr-13 2:13am    
Thanks very much, worked a treat.
Aarti Meswania 4-Apr-13 2:15am    
welcome!
Glad to help you! :)
F. Xaver 4-Apr-13 2:21am    
DirectCast (Me.Controls.Find("Label" & No,True).GetValue(0),Label).Text = DirectCast (sender,TextBox).Text

that Control.Find is awsome. haven't seen in before.
but there is no need to search the source Textbox ;)
Aarti Meswania 4-Apr-13 2:23am    
right It will work
Just copy-paste habit... :)
Aarti Meswania 4-Apr-13 2:25am    
I have update my answer. :)
Use one TextChanged Event.
And cast the sender to TextBox with in that event.
Then with it's name assign the values to appropriate labels.
 
Share this answer
 
Private Sub txt_a_qty_TextChanged(sender As Object, e As EventArgs) Handles txt_a_qty.TextChanged
txt_a_qty.Text = Val(txt_b_qty.Text) - Val(txt_so_qty.Text)
End Sub

this is mean the available quantity equal the buyed quantity minus the sold quantity... what is the right code to not exceed the sold quantity than the available quantity?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900