Results 1 to 3 of 3

Thread: Class '' cannot be indexed because it has no default property

  1. #1

    Thread Starter
    Registered User Hoshi17's Avatar
    Join Date
    Oct 2018
    Posts
    3

    Class '' cannot be indexed because it has no default property

    Hello! I'm creating a Memory Game for our project. I'm new to Visual basic and can't really create a decent program without asking for help. So the error Class 'System.Windows.Forms.PictureBox' cannot be indexed because it has no default property. All imgCardBack have error. I really need your help. Thank you. Here is the code:


    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


    imgSelection(0) = imgselection1
    imgSelection(1) = imgselection2
    imgSelection(2) = imgselection3
    imgSelection(3) = imgselection4


    imgCardBack(0) = imghidden1
    imgCardBack(1) = imghidden2
    imgCardBack(2) = imghidden3
    imgCardBack(3) = imghidden4
    imgCardBack(4) = imghidden5
    imgCardBack(5) = imghidden6
    imgCardBack(6) = imghidden7
    imgCardBack(7) = imghidden8
    imgCardBack(8) = imghidden9
    imgCardBack(9) = imghidden10
    imgCardBack(10) = imghidden11
    imgCardBack(11) = imghidden12
    imgCardBack(12) = imghidden13
    imgCardBack(13) = imghidden14
    imgCardBack(14) = imghidden15
    imgCardBack(15) = imghidden16
    imgCardBack(16) = imghidden17
    imgCardBack(17) = imghidden18
    imgCardBack(18) = imghidden19
    imgCardBack(19) = imghidden20

    End Sub

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,024

    Re: Class '' cannot be indexed because it has no default property

    Presumably you were intending to declare 'imgCardBack' as a PictureBox array but it appears that you have declared it just as a PictureBox instead. You probably did this:
    vb.net Code:
    1. Dim imgCardBack As PictureBox
    instead of this:
    vb.net Code:
    1. Dim imgCardBack As PictureBox()
    The thing is, the second code snippet would create a variable of the right type but it still doesn't actually create an array. You must specify the size of an array in order to create one. Maybe you should try explaining what you're actually trying to achieve and showing all the relevant code, rather than making us work out your aim from some of the code that doesn't actually do it.

  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,013

    Re: Class '' cannot be indexed because it has no default property

    I'm surprised you would need 20 images for the back of the cards. Usually all the backs of the cards are the same, so you should only need one image.
    Since it is a memory game and you have 20 cards, I would expect you would have 10 images that you have to match.

    I would expect 20 pictureboxes, that just represent the cards. You would preset them all to the back image.
    Then when one was clicked on you would set it to whatever image out of the 10 that card should be. (You would have some array that would randomly mapped the numbers 0 to 9, twice, to the 20 car position.)
    When they clicked on a second card, you would likewise set it to the image that is assigned to it.
    Then, do what ever processing you do for a match, or mismatch, and if mismatched, you would assign the back image to the cards again to hide them.

    But, you may be planning a different mechanism for your implementation, but in any case, I would not see the need for 20 back images regardless.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width