譬如有以下DataGrid:DG1、DG2、DG3.....DG10,想这样:
Dim dgs(9) as DataGrid
Dim i As Integer
For i=1 to 10
dgs(i-1)=xxxx("DG" & i.ToString)
Next
xxxx代表转换,这个转换怎样实现???
...全文
464打赏收藏
怎样通过名字访问对象
譬如有以下DataGrid:DG1、DG2、DG3.....DG10,想这样: Dim dgs(9) as DataGrid Dim i As Integer For i=1 to 10 dgs(i-1)=xxxx("DG" & i.ToString) Next xxxx代表转换,这个转换怎样实现???
窗口上有名为Textbox1~TextBox4的四个输入框,代码如下
——————————————————————————
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim txt(3) As TextBox
Dim obj As Object
For Each obj In Me.Controls
If TypeOf (obj) Is TextBox Then
Dim id As Integer = CType(obj, TextBox).Name.Substring(obj.name.ToString.Length - 1, 1)
txt(id - 1) = obj
End If
Next
For i As Integer = 0 To txt.Length - 1
Console.WriteLine(txt(i).Text)
Next
End Sub