title: Index was out of range. Must be non-negative and less than the size of the collection. Arg_ParamName_Name
body: <p>I'm trying to add Items to my item list then load images in the inventory but keep ending up with this error and I'm not sure why. I'm making a game which uses visual basic and forms.</p>
  <pre><code>Public Class InvInterface
  Public ItemMax As Integer = 9 'Number of inventory slots
  Public Items As New List(Of Items)
  
  
  
  Public Sub Add(Newitem As Items)
      If Items.Count &lt;= ItemMax Then
          For Each I As Items In Items
              If I.Name = Newitem.Name Then
                  If I.IsStackable = True And I.ItemCount &lt; 16 Then
                      I.ItemCount += 1
                      Exit Sub
                  Else
                      Items.Add(Newitem)
                      Exit Sub
                  End If
              End If
          Next
          Items.Add(Newitem)
      End If
  End Sub
  Public Sub Remove(ItemID As Items)
      If Items.Item(Items.IndexOf(ItemID)).ItemCount &gt; 0 Then
          Items.Item(Items.IndexOf(ItemID)).ItemCount -= 1
      Else
          Items.RemoveAt(Items.IndexOf(ItemID))
      End If
  End Sub
  Public Sub UpdateInv()
      For i = 1 To ItemMax
          If 0 &lt; Items.Count Then
              Select Case i
  
                  Case 1
                      Inv11.Image = Items(i).ImageAsset
                  Case 2
                      Inv12.Image = Items(i).ImageAsset
                  Case 3
                      Inv13.Image = Items(i).ImageAsset
                  Case 4
                      Inv21.Image = Items(i).ImageAsset
                  Case 5
                      Inv22.Image = Items(i).ImageAsset
                  Case 6
                      Inv23.Image = Items(i).ImageAsset
                  Case 7
                      Inv31.Image = Items(i).ImageAsset
                  Case 8
                      Inv32.Image = Items(i).ImageAsset
                  Case 9
                      Inv33.Image = Items(i).ImageAsset
  
              End Select
  
  
  
          End If
      Next
  End Sub
  </code></pre>
  <p>Dim Cobblestone As New Items
  Dim WoodPlank As New Items
  Dim currancy As New Items
  Dim Flower As New Items
  Dim CactusPlant As New Items
  Public Sub initialiseItems()</p>
  <pre><code>    With cobblestone
          .Item = ItemClass.Blocks
          .Name = &quot;Stone&quot;
          .Description = &quot;Comes from the ground made from rock&quot;
          .IsStackable = True
          .ImageAsset = My.Resources.Stone
      End With
      With WoodPlank
          .Item = ItemClass.Blocks
          .Name = &quot;Wood&quot;
          .Description = &quot;Wood planks can be used to create structures&quot;
          .IsStackable = True
          .ImageAsset = My.Resources.Wood
      End With
      With Flower
          .Item = ItemClass.Usable
          .Name = &quot;Flowers&quot;
          .Description = &quot;Gives small health boost&quot;
          .IsStackable = True
          .ImageAsset = My.Resources.HumanBrainIcon
      End With
      With currancy
          .Item = ItemClass.Specials
          .Name = &quot;Gold Coin&quot;
          .Description = &quot;These can be used at a merchant shop or casino&quot;
          .IsStackable = True
          .ImageAsset = My.Resources.Coin
      End With
      With CactusPlant
          .Item = ItemClass.Usable
          .Name = &quot;Cactus&quot;
          .Description = &quot;Gives a substantial health boost&quot;
          .IsStackable = True
          .ImageAsset = My.Resources.Florance
      End With
  End Sub
  </code></pre>