The problem is the scope of your plane
variable. Currently, you are declaring it as a local variable inside the Form1_Load
method. By doing so, that makes it inaccessible from any other method anywhere in your application. Also, since you never set any other variable (with a greater scope) to the object, that array object will get cleaned up at the garbage collector's earliest convenience and the array will cease to exist. The way to correct it is to declare the variable as a field of your class rather than as a local variable to a method. When it is declared as a field to the class, it will be within the scope of all of the methods in the class. For instance:
Public Class Form1
Private plane(4) As airplane ' This is a field of the class, scoped to all methods in the class
Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
plane(0) = New airplane("he112", 1, "", 10, 10, 0, 0, 100)
' ...
End Sub
End Class
For more information on scope. See this article in the MSDN. Also, this article looks applicable too.
I don't think there is anything particularly wrong with doing that work in the Load
event handler. As long as it doesn't take a long time to execute it, I would say that is a very reasonable place to put it. If it did take a long time to run that code, for some reason, it would be better to do it in a background worker which is started by the Shown
event so that you don't slow down the showing of the form.