Hey Guys,
I am new to vb.net. I am currently programming Space Invaders. Firstly i have two forms What is code for linking form 1 to form 2?
Secondly i have coded and tried to understand arrays. I currently Have
It is telling me there is an error with the line Enemy(WhichEnemy).Top += 4
It is saying the object reference is not set to an instance of an object???
There is a form load code which goes which this code.
Again have no idea what is wrong. Just trying to make enemy's move with arrays instead of single programming. Please Help
I am new to vb.net. I am currently programming Space Invaders. Firstly i have two forms What is code for linking form 1 to form 2?
Secondly i have coded and tried to understand arrays. I currently Have
VB.NET:
Private Sub tmrUFO_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrUFO.Tick
Randomize()
Dim WhichEnemy As Integer = Int(Rnd() * 6) ' random number 0-5
Enemy(WhichEnemy).Top += 4 ' move 4 pixels down
If Enemy(WhichEnemy).Top > Me.Height Then ' gone off bottom of form
Enemy(WhichEnemy).Top = -Enemy(WhichEnemy).Height ' send to top of form
End If
It is saying the object reference is not set to an instance of an object???
There is a form load code which goes which this code.
VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim obj As Object, I As Integer = 0, J As Integer = 0
' all controls on the form
If TypeOf obj Is PictureBox Then ' only check for pictureboxes
If obj.Tag = "spaceship" Then
Enemy(I) = obj ' add this object to the Enemy array
I += 1 ' advance ready for next element
End If
End If
Last edited by a moderator: