title: group directory files into sets VB.Net
body: <p>I am trying to populate 3 "Small images" into 1 large image. The images have been set in order.
  The problem is that in this case, the directory contains 10 "Small images". how can I load 10 images, separate them into groups of three, save my "large Image" and continue with the next three "small images"? </p>
  
  <p>UPDATE: 2</p>
  
  <pre><code> Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
          Dim files As String() = Directory.GetFiles("C:\pics\")
  
          For i As Integer = 0 To files.Length - 1 Step 3
              Dim file1 As String = Nothing
              Dim file2 As String = Nothing
              Dim file3 As String = Nothing
              file1 = files(i)
              If i &lt; files.Length - 1 Then
                  file2 = files(i + 1)
              End If
              If i &lt; files.Length - 2 Then
                  file3 = files(i + 2)
              End If
  
              'Here the background is created and filled.
              Dim img As New Bitmap(2400, 3000)
              Dim img_back As Graphics = Graphics.FromImage(img)
              img.SetResolution(300, 300)
              img_back.FillRectangle(Brushes.White, 0, 0, 2400, 3000)
              ' Sets Spot names for ech ticket
              Dim Ticket_1 As New Bitmap(file1, True)
              Dim Ticket_2 As New Bitmap(file2, True)
              Dim Ticket_3 As New Bitmap(file3, True)
  
              'This creates New merged image
              Dim g As Graphics = Graphics.FromImage(img)
              g.DrawImage(Ticket_1, 500, 200)
              g.DrawImage(Ticket_2, 500, 1000)
              g.DrawImage(Ticket_3, 500, 1800)
  
              'We Save rendered image and display on picturebox
              img.Save("C:\pics\list\" &amp; i &amp; "NewTicket List.jpg")
              PictureBox1.Image = img
          Next
          'PictureBox1.Image.Save("C:\pics\New" + 1)
          MsgBox("All Done!")
  
      End Sub
  </code></pre>
  
  <p>if  array contains non amount of images divisible by 3 i get a null error
  How can i deal with the files being null Basically allowing them to be null?</p>
  
  <p>UPDATE 3</p>
  
  <p>to get around the value being null i Changed </p>
  
  <pre><code> Dim files As String() = Directory.GetFiles("C:\pics\")
  
          For i As Integer = 0 To files.Length - 1 Step 3
              Dim file1 As String = Nothing
              Dim file2 As String = Nothing
              Dim file3 As String = Nothing
              file1 = files(i)
              If i &lt; files.Length - 1 Then
                  file2 = files(i + 1)
              End If
              If i &lt; files.Length - 2 Then
                  file3 = files(i + 2)
              End If
  </code></pre>
  
  <p>to this</p>
  
  <pre><code> Dim files As String() = Directory.GetFiles("C:\pics\")
  
          For i As Integer = 0 To files.Length - 1 Step 3
              Dim file1 As String = "C:\pics\NoImage\NoImage.jpg"
              Dim file2 As String = "C:\pics\NoImage\NoImage.jpg"
              Dim file3 As String = "C:\pics\NoImage\NoImage.jpg"
              file1 = files(i)
              If i &lt; files.Length - 1 Then
                  file2 = files(i + 1)
              End If
              If i &lt; files.Length - 2 Then
                  file3 = files(i + 2)
              End If
  </code></pre>
  
  <p>how can i allow  the Ticket_1 to be null?</p>