Using a Variable for a control name works unless the control is in a panel or a tab.

  • Thread starter Thread starter JeffNelson154
  • Start date Start date
J

JeffNelson154

Guest
This code works just fine on a form

Dim x As Integer = 1
For x = 1 To 3
Dim TextBoxName As TextBox = Controls("txtCvar" & x)
TextBoxName.Text = "This Works"
Next



If I put the textboxes in a Panel or a Tab, I get errors...

System.NullReferenceException: 'Object reference not set to an instance of an object.'
TextBoxName was Nothing.


Any Ideas on how to correct that?

Continue reading...
 
Back
Top