You're going about this the wrong way ...
Think about a deck of cards ... there are suites ...
Dim Suites As String() = New String() {"Spade", "Heart", "Club", "Diamond"}
and there are the face values
Dim CardNames() As String = New String() {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"}
This lends itself to
KeyValuePairs - see
dotnetperls.com - keyvaluepairs[
^]
Then you have the deck as a whole ... think of this as a list of the cards, which we have already discovered are "keyvaluepairs" (see the same link above)
Dim Cards As List(Of KeyValuePair(Of String, Integer)) = New List(Of KeyValuePair(Of String, Integer))
Because each card is a keyvaluepair of it's "name" = Suite + face title, plus it's nominal value
Dim ACard As KeyValuePair(Of String, Integer)
we can fill our deck of cards like this
Dim ACard As KeyValuePair(Of String, Integer)
For s = 0 To 3
Dim suite As String = Suites(s)
For i As Integer = 1 To 13
ACard = New KeyValuePair(Of String, Integer)(suite + CardNames(i - 1), IIf(i >= 10, 10, i))
If i = 1 Then ACard = New KeyValuePair(Of String, Integer)(suite + CardNames(i - 1), 11)
Cards.Add(ACard)
Next
Next
For i As Integer = 0 To Cards.Count - 1
Debug.Print(i.ToString() + " : " + Cards(i).Key + " : " + Cards(i).Value.ToString())
Next
(If you are not familiar with the ternary operator iif here is a
reference[
^])
That
Debug.Print
bit at the end is going to produce
0 : SpadeAce : 11
1 : Spade2 : 2
2 : Spade3 : 3
3 : Spade4 : 4
4 : Spade5 : 5
5 : Spade6 : 6
...
46 : Diamond8 : 8
47 : Diamond9 : 9
48 : Diamond10 : 10
49 : DiamondJack : 10
50 : DiamondQueen : 10
51 : DiamondKing : 10
So hopefully you can see that we have a "deck of cards", each card has a unique identifier (the first number), a name (e.g. SpadeAce) and a Value (11,2,3 etc)
Now when I get a random card out of the deck I'm going to use this function
Public Function GetRandom(ByVal Min As Integer, ByVal Max As Integer) As Integer
Static Generator As System.Random = New System.Random()
Return Generator.Next(Min, Max)
End Function
[NOTE - I found this some time ago via Google but now can't find who to credit it to - happy to update this solution if anyone knows who deserves the credit]
So my button
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim ranCard As Integer = GetRandom(0, Cards.Count - 1)
Debug.Print("Card is : " + Cards(ranCard).Key + " : Value = " + Cards(ranCard).Value.ToString())
End Sub
produces results like this ...
Card is : Club4 : Value = 4
Card is : Club7 : Value = 7
Card is : DiamondKing : Value = 10
Card is : Diamond9 : Value = 9
Card is : Diamond2 : Value = 2
Card is : Heart6 : Value = 6
Now that I've given you a solution I do need to justify my comment "You're going about this the wrong way"
Firstly ... in forums like this, only post the relevant code ... you posted a lot of empty functions ... that just gets in the way of people trying to understand what your problem is and they are less likely to try and help (human nature!)
Next have a good look at your function
RandomCards()
... when you have hard-coded values like that you want to think about moving them out of a function that can be called many times and into some sort of initialisation routine.
Lastly, you went for a single-dimension array ... that can only hold one type of information - hence your problem with assigning values. Research some of the collection types available in .NET ... Lists and Dictionaries (as you can see above) can be very powerful