我正在将一些代码从我在VBA中编写的应用程序转移到vb.net。在我的原始应用程序中,通过执行以下操作,我能够遍历一组100个复选框:
Dim c As Control
Dim nm As String
For busRuleIdx = 1 To 100
nm = "CheckBox" & busRuleIdx
Set c = Form2.Controls(nm)
If SomeRule Then
c.Value = True
Else
c.Value = False
End If
Next
我在VB.Net中尝试过类似的东西:
Dim myForm As Form2
Dim nm As String
Dim c As CheckBox
myForm = New Form2()
For busRuleIdx = 1 To 100
nm = "CheckBox" & busRuleIdx
c = myForm.Controls(nm)
If SomeRule Then
c.Checked = True
Else
c.Checked = False
End If
Next
然而,这总是导致c =无。我在引用当前表单时看到上述工作正常,即me.Controls(nm) - 但是在引用另一个表单时如何使用这种类型的代码 - 在Form2上面的示例中?
谢谢,
skinicod