Hi guys, can you please help me out.
I have 14 panels in my form, the user then input a number in the textbox. Then this textbox will now determine how many panels will be enable. My formula would be, userinputtextbox/0.5=panels to be open. Example: 3/0.5=6.

So far this is my code:

for x = 1 to UserInputTextbox.text
CType(Me.Controls("P" & x.ToString ), Panel).Enabled = True

But I got this error:
Object reference not set to an instance of an object.
And it highlighted my Ctype code. What I am lacking?

PS. The names of my panels were P1, P2.... P14 =)

For x As Integer = 1 To CInt(UserInputTextbox.Text)
            For Each ctl As Control In Me.Controls '// Loop thru all Controls on Form.
                If TypeOf (ctl) Is Panel Then '// Locate Panels.
                    If ctl.Name = "P" & x.ToString Then
                        ctl.Enabled = True
                        Exit For
                    End If
                End If

Edited 5 Years Ago by codeorder: n/a

Hi thank you for this code. Another approach would be:

For i = 1 to CInt(UserInputCombobox.text)
   CType(Me.GroupBox1.Controls("P" & i.ToString), Panel).Enabled = False

This one is shorter for those guys out there. But both codes are doing great. Thank you again. =)

kudos for that code sample.:)
This question has already been answered. Start a new discussion instead.