For a project I require the creation of textboxes at run time, to this end I have used this code;
Dim AOP As Integer = GlobalVariables.AOP
Dim tb(11, 11) As TextBox
Dim LocationX As Integer
Dim LocationY As Integer
Dim count As Integer = 2
LocationX = 10
LocationY = 10
tb(1, 0).Name = "txtRoot"
tb(1, 0).Size = New Size(170, 20)
tb(1, 0).Location = New Point(LocationX, LocationY)
tb(1, 0).Visible = False
I am then able to loop it using this For loop;
For i = 1 To AOP
If count > AOP Then
Else
If i = AOP Then
LocationY = LocationY + 10
LocationX = 10
tb(count, 0).Name = "txtXValue" & 0 & "YValue" & count
tb(count, 0).Size = New Size(170, 20)
tb(count, 0).Location = New Point(LocationX, LocationY)
Controls.Add(tb(count, 0))
count = count + 1
i = 1
Else
LocationX = LocationX + 10
tb(count, i).Name = "txtXValue" & i & "YValue" & count
tb(count, i).Size = New Size(170, 20)
tb(count, i).Location = New Point(LocationX, LocationY)
Controls.Add(tb(count, i))
End If
End If
Next
This works in theory, however, when the code reaches the line;
tb(1, 0).Name = "txtRoot"
It returns the error 'Object reference not set to an instance of an object' I am wondering if there is anyway around this? or if this way of creating textboxes isn't possible? Any help would be appreciated.