title: visual basic 2008 control arrays
body: <p>I'm looking at controlling properties of an array of buttons in VB 2008 (express). I have been looking at the sample code from a whitepaper at MS, and it kind of makes my head spin compared to what was done in VB6! (and yes I'm an amateur, so please forgive the poor coding and what is probably a simple question for the experienced here...)</p>
  
  <p>If I'm reading it correctly, the correct way to do it now is to create a separate class, create constructors, etc. for that class, then instantiate it in the project?</p>
  
  <p>I'm trying to use a relatively simple array like this:</p>
  
  <pre><code>    'Create buttons
      'Dim btn(30) As Button
      'For i As Integer = 0 To 29
      '    btn(i) = New Button()
      '    btn(i).Width = 100
      '    btn(i).Height = 30
      '    btn(i).Text = i + 1
  
      '    btn(0).Left = 120
      '    btn(0).Top = 100
  
      '    If i &gt;= 1 And i &lt;= 14 Then
      '        btn(i).Left = 120
      '        btn(i).Top = btn(0).Top + (i * 30)
      '    End If
  
      '    If i = 15 Then
      '        btn(15).Left = 235
      '        btn(15).Top = 100
      '    End If
  
      '    If i &gt;= 16 And i &lt;= 29 Then
      '        btn(i).Left = 235
      '        btn(i).Top = btn(0).Top + ((i Mod 15) * 30)
      '    End If
      '    Me.Controls.Add(btn(i))
  
      'Next
  </code></pre>
  
  <p>If I put it into the load method, then I can't access it from another button, because I think it's in a private subroutine when this snippet is in the load subroutine? Is there a simple way to just have this code so that the btn(i) array is accessible from other functions in the form?</p>