I'm writing a program where the settings of a spreadsheet-like field of textboxes are changed using two for loops, and I can't for the life of me figure out why it's not working.I have tried declaring the txt variable and name variable in different orders using different methods, but nothing seems to work. With this code, I get the error, "Object reference not set to an instance of an object." Can somebody help me? Thank you.
' For loop repeats for each row For i As Integer = 1 To rows Step +1 ' Creates unicode character code for row naming scheme (Numeric) Dim rowsCode As String = "&H" & (rows + 30).ToString() ' For loop repeats for each text box in row For j As Integer = 1 To columns Step +1 ' Creates unicode character code for column naming scheme (Alphabetic) Dim columnsCode As String = "&H" & (i + 40).ToString() ' Creates text box variable and sets settings Dim name As String = "txt" & ChrW(columnsCode) & ChrW(rowsCode) Dim txt As TextBox = Me.Controls(name) txt.Name = "txt" & ChrW(columnsCode) & ChrW(rowsCode) txt.Visible = True txt.Enabled = True txt.BringToFront() Next Next