0

The error I'm getting is "System.NullReferenceException: 'Object reference not set to an instance of an object.'" This is at the line where I try to set the image as a bitmap. I've tried changing the location of the image multiple times and still doesn't help.

 Dim monkeys(4) As PictureBox
    For i = 0 To 4
        monkeys(i).Image = New Bitmap("H:\Monkey Casino\Monkey Casino\bin\Debug\monkey.bmp")

        monkeys(i).Width = 92
        monkeys(i).Height = 102
        monkeys(i).Top = 579
        monkeys(i).BackColor = Color.Transparent
    Next
    monkeys(1).Left = 48
    monkeys(2).Left = 237
    monkeys(3).Left = 425
    monkeys(4).Left = 609
    monkeys(5).Left = 793
Jayeet
  • 11
  • 1
  • 3

1 Answers1

0

You never actually create any PictureBoxes.

If I give you an empty egg carton, does that mean that you can magically scramble some eggs? Of course not. If you never put any eggs in the carton then you can never get any eggs out.

That's exactly what you're doing. You create the egg carton (the array) but you never put any eggs (the PictureBoxes) into it so of course you can't get a PictureBox out of it to set a property. Think of an array as a group of variables. You have to initialise each element the same way you would a variable.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46