如何用循环创建var(例如:Dim a1,a2,a3 with loop)

时间:2010-07-21 12:52:50

标签: vb.net

Dim count As Integer
For count = 1 To 10 Step 1
    Dim But+count As New Button
    myButton+count.Width = 100*count
    myButton+count.Height = 20*count
    myButton+count.Top = 50 *count
    myButton+count.Left = 50*count
    Me.Controls.Add(myButton+count)
Next

Dim But+count As New Button =>如何使它工作

2 个答案:

答案 0 :(得分:4)

如何在循环的每次迭代中创建一个数组并在'ith'位置实例化该项。它不会是a1,a2,a3,......;但它会是[1],[2],[3],....

答案 1 :(得分:2)

Dim buttons(9) As Button
For count As Integer = 0 To 9
        Dim button As New Button
        button.Width = 100*count
        button.Height = 20*count
        button.Top = 50 *count
        button.Left = 50*count
        Me.Controls.Add(button)
        buttons(count) = button
Next