VB6 to 2005 Control Arrays

Can someone please tell me a little bit more about Control Arrays after upgrading VB6 to 2005 There are 7 images which use the same click sequence, and they are all named Card. The following is a sample of the code:

VB6:

Private Sub Card_Click(Index As Integer)
If Card(Index).Picture = Image2.Picture Then
Safenum = Safenum + 100
Card(Index).Picture = Pile(1).Picture
Call Nextmove
Call Enemymove
Exit Sub
End If

End Sub

VB 2005 after conversion:

Private Sub Card_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Card.Click

If Card(Index).Image.equals(Image2.Image) Then

Safenum = Safenum + 100

Card(Index).Image = Pile(1).Image

Call Nextmove()

Call Enemymove()

Exit Sub

End If

End Sub

After conversion, none of the Card functions work and they were renamed to _Card_[Number]. I know VB2005 doesn't support Control Arrays, so how can I make it so that VB 2005 does the same function VB 6 does

Thanks



Answer this question

VB6 to 2005 Control Arrays

  • bunschoten

    Perhaps if thePictureBox.Image = null I dunno, I don't use them, I think they are a waste of space. I just load bitmaps and draw them to my window :-)

  • MannyH

    Something that has been bugging me I have no idea what .NET is. Is it any Visual Studio 2005 program


  • Sans

    This is kind of embarrasing, but how to you set your thread so the icon says "Question Answered "


  • TimBW

    Private Sub Card_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Card.Click

    ' I'm not sure if you need to cast eventSender to be a Card, or how that works in VB.NET.

    If eventSender.Image.equals(Image2.Image) Then

    Safenum = Safenum + 100

    Card(Index).Image = Pile(1).Image

    Call Nextmove()

    Call Enemymove()

    Exit Sub

    End If

    End Sub



  • Be_Ta

    I deleted what was causing the problem and unfortunatly, I still don't quite understand what you mean. Could you please copy & paste, then edit the code that I posted in my first post


  • katarn85

    Sure. But, you don't need a control array, in fact I'm told you shouldn't use them in .NET. Your controls are in the controls collection for the form, and in any case, you can reference the control that generated the event directly, as it's passed in to your event handler.

  • someoneontheinternet

    I am trying to check if what you said works, but I keep getting an error. How can I use an If statement to check if a picturebox is blank
  • Gad D Lord

    The left most button in the group you click to reply should say 'mark as answer' :-)

  • Chadk

    You don't need arrays of controls. Your form has a Controls collection, if you need to iterate over them for any reason. However, when an event is fired, the first parameter that is passed in is an object, and it's the object that fired the event. So, in this case, it's the card that you clicked on. You just need to cast it to be a Card, and you can use it. Actually, with Vb, you may just be able to request the properties you want, VB is loosely typed.



  • Christopher McGinnis

    I accidently deleted some code. Straight after the Handles statement on the next line, it has:

    Dim Index As Short = eventsender.GetIndex(eventsender)

    Sorry

    If it's any help, the picture boxes are named Card_1, Card_2, etc to Card_7


  • Ruma Pal

    Could you please explain this in a bit more detail I'm OK with VB6, but only just started 2005.

    Just clarifying, I want all seven of the Cards to do the same thing, preferably in the same sub. I have a lot more Control Arrays in the project and i rather wouldn't do each one manually.


  • Dan_Seattle

    Thanks for helping me :). The code you posted worked.
  • dkfitzgerald

    eventSender is the item that sent the message. Cast it to be a Card, and then do the check to see if the image is the same ( if I read your code correctly )



  • Potluri

    .NEt is the framework that all VB.NEt programs compile to, and that your clients need to install to run your programs.



  • VB6 to 2005 Control Arrays