Hi
I am a new user to
vb 2010. I want to be able to use a loop and reference controls using a string. The following code works for textboxes.
Code:
dim myControl as Control
dim ControlName as string
dim LoopCount as Integer
For LoopCount = 1 to 3
ControlName = "TextBox" & cStr(LoopCount)
myControl = Me.Controls.Item(ControlName)
myControl.text = "some string here"
Next
However, If I try the same thing with a checkBox control it generates the Following error;
'Checked' is not a member of 'System.Windows.Forms.Control'.
on the line ,"IF myControl.checked = True then"
Code:
dim myControl as Control
dim ControlName as string
dim LoopCount as Integer
For LoopCount = 1 to 3
ControlName = "CheckBox" & cStr(LoopCount)
myControl = Me.Controls.Item(ControlName)
IF myControl.Checked = True Then
execute some code here
End IF
Next
Any help would be greatly apreciated