title: Error VB.NET index out of bounds
body: <p>I am in a kind of situation here. I have an "index is out of bounds" error and I don`t know what causes it. I guess it has something to do with the tags.</p>
  
  <p>Normally the tag represents a number. If I divide that number by the number of columns, it gives me back the row of the button that I clicked. If I take the mod of that tag it should return me the column of the clicked button. But something is wrong and I can`t figure out what. I hope someone can help me out with this. Thanks in advance.</p>
  
  <pre><code>Public Class Form1
      Dim AANTAL_KOLOMMEN As Integer = 8
      Dim AANTAL_RIJEN As Integer = 8
      Dim Button1 As Button
      Dim tel As Boolean
      Dim value1 As Integer
      Dim value2 As Integer
      Dim myButtons(AANTAL_RIJEN, AANTAL_KOLOMMEN) As Button
  
  
  
      Public Function zetNieuw(rij As Integer, kolom As Integer) As Button
          Dim nieuweKnop As New Button()
          nieuweKnop.Width = 40
          Me.Controls.Add(nieuweKnop)
          nieuweKnop.Name = "Btn_" &amp; rij &amp; "_" &amp; kolom
          nieuweKnop.Left = kolom * nieuweKnop.Width
          nieuweKnop.Top = rij * nieuweKnop.Width
          nieuweKnop.Height = nieuweKnop.Width
          nieuweKnop.Text = ""
          AddHandler nieuweKnop.MouseDown, AddressOf Klik
          If rij = 3 And kolom = 3 Then
              nieuweKnop.BackColor = Color.Black
          End If
          If rij = 4 And kolom = 4 Then
              nieuweKnop.BackColor = Color.Black
          End If
          If rij = 3 And kolom = 4 Then
              nieuweKnop.BackColor = Color.White
          End If
          If rij = 4 And kolom = 3 Then
              nieuweKnop.BackColor =
                  Color.White
          End If
          nieuweKnop.Tag = (kolom + (rij * AANTAL_KOLOMMEN))
          Return nieuweKnop
  
  
      End Function
  
  
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          For Me.value2 = 0 To AANTAL_RIJEN - 1 Step 1
              For Me.value1 = 0 To AANTAL_KOLOMMEN - 1 Step 1
  
                  myButtons(value2, value1) = Me.zetNieuw(value2, value1)
              Next
          Next
  
      End Sub
      Private Sub Klik(sender As Object, e As MouseEventArgs)
          Dim knop As Button = sender
          Dim value As String = knop.Tag
  
          If myButtons(Tag / AANTAL_KOLOMMEN, (Tag Mod AANTAL_KOLOMMEN) - 2).BackColor = Color.Black Or myButtons((Tag / AANTAL_KOLOMMEN - 2), Tag Mod AANTAL_KOLOMMEN).BackColor = Color.Black Or myButtons((Tag / AANTAL_KOLOMMEN) - 2, (Tag Mod AANTAL_KOLOMMEN) - 2).BackColor = Color.Black Then
              knop.BackColor = Color.Black
  
          ElseIf myButtons(Tag / AANTAL_KOLOMMEN, (Tag Mod AANTAL_KOLOMMEN) - 2).BackColor = Color.White Or myButtons((Tag / AANTAL_KOLOMMEN - 2), Tag Mod AANTAL_KOLOMMEN).BackColor = Color.White Or myButtons((Tag / AANTAL_KOLOMMEN) - 2, (Tag Mod AANTAL_KOLOMMEN) - 2).BackColor = Color.White Then
              knop.BackColor = Color.Black
          End If
  
  
  
      End Sub
  
  
  
  
  End Class
  </code></pre>