A Sub executes only partly

wwhelp

New member
Joined
Feb 18, 2013
Messages
3
Programming Experience
1-3
I set TextBox1.Text in design time.
When I start my VB.Net program including following Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
TextBox2.Text = "string2"
Label4.Text = "string4"
End Sub

TextBox2 will show "string2" but Label4 will show nothing!
Can you help?
 
Thank you.

That is all in my test project.
You seems not believe? Please try that:

You need TextBox1, TextBox2 and Label4, and set some string to TextBox1.Text in design time.
When you start your VB.Net program, before doing anything, following Sub will fire

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
TextBox2.Text = "string2"
Label4.Text = "string4"
End Sub

and you should be able to reproduce my problem.
 
I just tested it and it worked as you would expect for me. I added TextBox1, TextBox2 and Label1 in that order. I set the Text of TextBox1 to "First" and I added this event handler:
VB.NET:
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    TextBox2.Text = "Second"
    Label1.Text = "Third"
End Sub
When I ran the and the form displayed, TextBox1 contained "First", TextBox2 contained "Second" and Label1 contained "Third".

I suspect that what's happening in your case is that the Text of the Label is not set to an empty String in in the designer. Any property values you set in the designer are executed in code during the constructor. If you have set the Text of the Label in the designer then it will be set in code, probably after that event handler is executed. That would mean that the Text of the Label is being set twice. Try right-clicking on the Text property of the Label and selecting Reset to clear it and running the project again.
 
Back
Top