What is the syntax of the following code?

Tator

Member
Joined
May 14, 2011
Messages
5
Programming Experience
Beginner
VB.NET:
For Accounts As Integer = 1 To 10
            If Cbx1.Checked = True Then Call Login1()
        Next
What I want to do with this is run the loop through all 10 Checkboxes Cbx1>Cbx10.
How do I use the & to do this so where the number 1 is I can replace with Accounts variable?
 
The controls property of your form can be referenced using a string:

VB.NET:
For Accounts as integer = 1 to 10
Dim ctlstr as String = "Cbx" & Accounts
Dim cb as CheckBox = DirectCast(Me.Controls(ctlstr), CheckBox)
If cb.checked = True Then Call Login1()
Next Accounts

I realize that you want to dynamically call a function and this will need to be done through a Select statement or through using delegates. A delegate is an object that points to a method and you can dynamically access a method using a delegate.
 
Back
Top