Try this. Create a new project and add a Button to the form. Now replace the form code with this:Run that a click the button as many times as you like. That uses the principle in the first thread of mine I mentioned. Now here's some similar code that uses the second:Code:Public Class Form1 Private Enum CardSuit Hearts Clubs Diamonds Spades End Enum Private Enum CardFace Ace Two Three Four Five Six Seven Eight Nine Ten Jack Queen King End Enum Private Structure Card Public Face As CardFace Public Suit As CardSuit Public Overrides Function ToString() As String Return String.Format("{0} of {1}", Me.Face, Me.Suit) End Function End Structure Private deck As New List(Of Card) Private cardPicker As New Random Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.LoadDeck() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Me.deck.Count = 0 Then If MessageBox.Show("Would you like to reload the deck?", _ "Deck Empty", _ MessageBoxButtons.YesNo, _ MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then Me.LoadDeck() End If End If If Me.deck.Count > 0 Then Dim index As Integer = Me.cardPicker.Next(0, Me.deck.Count) Dim card As Card = Me.deck(index) Me.deck.RemoveAt(index) MessageBox.Show(card.ToString(), "Your Card") End If End Sub Private Sub LoadDeck() Dim card As Card For Each suit As CardSuit In [Enum].GetValues(GetType(CardSuit)) For Each face As CardFace In [Enum].GetValues(GetType(CardFace)) card = New Card card.Face = face card.Suit = suit Me.deck.Add(card) Next Next End Sub End ClassCode:Public Class Form1 Private Enum CardSuit Hearts Clubs Diamonds Spades End Enum Private Enum CardFace Ace Two Three Four Five Six Seven Eight Nine Ten Jack Queen King End Enum Private Structure Card Public Face As CardFace Public Suit As CardSuit Public Overrides Function ToString() As String Return String.Format("{0} of {1}", Me.Face, Me.Suit) End Function End Structure Private deck As New List(Of Card) Private cardPicker As New Random Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.LoadDeck() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Me.deck.Count = 0 Then If MessageBox.Show("Would you like to reload the deck?", _ "Deck Empty", _ MessageBoxButtons.YesNo, _ MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then Me.LoadDeck() End If End If If Me.deck.Count > 0 Then Dim card As Card = Me.deck(0) Me.deck.RemoveAt(0) MessageBox.Show(card.ToString(), "Your Card") End If End Sub Private Sub LoadDeck() Dim card As Card For Each suit As CardSuit In [Enum].GetValues(GetType(CardSuit)) For Each face As CardFace In [Enum].GetValues(GetType(CardFace)) card = New Card card.Face = face card.Suit = suit Me.deck.Add(card) Next Next Me.deck = Me.deck.OrderBy(Function() Me.cardPicker.NextDouble()).ToList() End Sub End Class




Reply With Quote