I’m trying to make a Blackjack game in VB. What I’d like to do is populate an array with each of the cards so that I can randomly generate integers and use those integers to pull an index from the array, basically randomly selecting a card.
My problem is that I can’t seem to get the images in the resources folder to go into the array. I’d like to use a For/Next loop to populate the array, as I would rather not manually assign all 52 cards to the array. I’m trying to do it like this:
Dim CardArray(51) As Image
Dim LoopIndexInteger As Integer
For LoopIndexInteger = 0 To 51
CardArray(LoopIndexInteger) = My.Resources.ResourceManager.GetObject(LoopIndexInteger)
Next
Where am I going wrong?
GetObjecttakes a resource name, not an index.You need to construct the name of one of your resources.
The simplest way to do that is to name the resources
Card0throughCard51and callGetObject("Card" & CInt(LoopIndexInteger))EDIT: You can also loop over
My.Resources.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, false, true), but it may not be in order.