Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27373

Help with loop through checkboxes in VB

$
0
0
Hello, I'm pretty much new to VB, haven't done any programing for many years - so please be gentle.

I've set up a form with 50 checkboxes. To save 100's of lines of If .. Then code I wouild like to query/manipulate the checkboxes with For Loops. The checkboxes are set up as follows:

Checkbox11 ... Checkbox15
Checkbox21 ... Checkbox25
etc, to
Checkbox111 .. Checkbox115

I've tried the code below but when run it comes up with an error 'Object reference not set to an instance of an object.' Which I do not understand.
Code:

        Dim x As Integer
        Dim y As Integer
        If ListBox1.Text = "All Instruments" Then
            For x = 10 To 110 Step 10
                For y = 2 To 5
                    Me.Controls("checkbox" & (x + y)).Visible = False
                Next y
            Next x
        End If

The code above is my adaption of the following, which I found on another site as a solution to a similar problem.
Code:

For I = 1 To 4
Me.Controls("Checkbox" & I).Value = True

Any help with this would be much appreciated. I'm using VS2012.

Viewing all articles
Browse latest Browse all 27373

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>