Hi guys! I am creating a game which include guns and bullets and I created everything. I want to have a shorter code which I am going to create a array of objects which are the bullets. Can someone help me? In VB6 it's possible to create an array of objects but I am having a hard time for VB 2008. Thank you for those who could help me.

Do you have any custom class for all this object?
If would be good to have it.
At least you can show us the code you have, and what would you like to change (comment it).

Oh sorry about that, the object I am referring to is the Image object. I am having a hard time coding each and every bullet that is in Image object it's like this

If RBullet1.Left >= Villain.Left And RBullet1.Top >= Villain.Top And RBullet1.Top <= (Villain.Top + Villain.Size.Height) Then
                RBullet1.Left = RBullet1.Top = 10000
                EnemyHP.Value = EnemyHP.Value - 5
                RBullet1.Visible = False
            End If
            If RBullet2.Left >= Villain.Left And RBullet2.Top >= Villain.Top And RBullet2.Top <= (Villain.Top + Villain.Size.Height) Then
                RBullet2.Left = RBullet2.Top = 10000
                EnemyHP.Value = EnemyHP.Value - 5
                RBullet2.Visible = False
            End If
            If RBullet3.Left >= Villain.Left And RBullet3.Top >= Villain.Top And RBullet3.Top <= (Villain.Top + Villain.Size.Height) Then
               
                RBullet3.Visible = False
            End If

The RBullet1, RBullet2, and RBullet3 are the image objects I have mentioned. I want to make it shorter. Please help me, thank you :)

Hi guys! I am creating a game which include guns and bullets and I created everything. I want to have a shorter code which I am going to create a array of objects which are the bullets. Can someone help me? In VB6 it's possible to create an array of objects but I am having a hard time for VB 2008. Thank you for those who could help me.

http://msdn.microsoft.com/en-us/library/487y7874(v=vs.80).aspx

I just had a similar situation. I had ten controls that I wanted to access in a loop so I did the following:

Dim PlayerRounds(9) As System.Windows.Forms.TextBox

PlayerRounds(0) = txtPlayer01Round
PlayerRounds(1) = txtPlayer02Round
PlayerRounds(2) = txtPlayer03Round
PlayerRounds(3) = txtPlayer04Round
PlayerRounds(4) = txtPlayer05Round
PlayerRounds(5) = txtPlayer06Round
PlayerRounds(6) = txtPlayer07Round
PlayerRounds(7) = txtPlayer08Round
PlayerRounds(8) = txtPlayer09Round
PlayerRounds(9) = txtPlayer10Round

then you can do stuff like

for each player in PlayerRounds
    player.Text = "0"
next
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.