Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Private Sub imgDice1_Click()
- ckBox1.Value = Not ckBox1.Value
- End Sub
- Private Sub imgDice2_Click()
- ckBox2.Value = Not ckBox2.Value
- End Sub
- Private Sub imgDice3_Click()
- ckBox3.Value = Not ckBox3.Value
- End Sub
- Private Sub imgDice4_Click()
- ckBox4.Value = Not ckBox4.Value
- End Sub
- Private Sub imgDice5_Click()
- ckBox5.Value = Not ckBox5.Value
- End Sub
- Private Sub ToggleControls(toggle As Boolean)
- ckBox1.Enabled = toggle
- ckBox2.Enabled = toggle
- ckBox3.Enabled = toggle
- ckBox4.Enabled = toggle
- ckBox5.Enabled = toggle
- imgDice1.Enabled = toggle
- imgDice2.Enabled = toggle
- imgDice3.Enabled = toggle
- imgDice4.Enabled = toggle
- imgDice5.Enabled = toggle
- End Sub
- Private Sub cmdNewGame_Click()
- ckBox1.Value = False
- ckBox2.Value = False
- ckBox3.Value = False
- ckBox4.Value = False
- ckBox5.Value = False
- Range("C12").Value = ""
- cmdRollDice.Enabled = True
- cmdNewGame.Enabled = False
- imgDice1.Picture = LoadPicture(Workbooks("PokerDice.xlsm").Path & "\" & "empty.bmp")
- imgDice2.Picture = LoadPicture(Workbooks("PokerDice.xlsm").Path & "\" & "empty.bmp")
- imgDice3.Picture = LoadPicture(Workbooks("PokerDice.xlsm").Path & "\" & "empty.bmp")
- imgDice4.Picture = LoadPicture(Workbooks("PokerDice.xlsm").Path & "\" & "empty.bmp")
- imgDice5.Picture = LoadPicture(Workbooks("PokerDice.xlsm").Path & "\" & "empty.bmp")
- End Sub
- Private Sub cmdRollDice_Click()
- Static numRolls As Integer
- Dim imageFile As String
- Dim imagePath As String
- imagePath = Workbooks("PokeDice.xlsm").Path & "\"
- numRolls = numRolls + 1
- Randomize
- If ckBox1.Value = False Then
- Range("B2").Value = Int(Rnd * 6) + 1
- imageFile = imagePath & Trim(Str(Range("B2").Value)) & ".bmp"
- imgDice1.Picture = LoadPicture(imageFile)
- End If
- If ckBox2.Value = False Then
- Range("C2").Value = Int(Rnd * 6) + 1
- imageFile = imagePath & Trim(Str(Range("C2").Value)) & ".bmp"
- imgDice2.Picture = LoadPicture(imageFile)
- End If
- If ckBox3.Value = False Then
- Range("D2").Value = Int(Rnd * 6) + 1
- imageFile = imagePath & Trim(Str(Range("D2").Value)) & ".bmp"
- imgDice3.Picture = LoadPicture(imageFile)
- End If
- If ckBox4.Value = False Then
- Range("E2").Value = Int(Rnd * 6) + 1
- imageFile = imagePath & Trim(Str(Range("E2").Value)) & ".bmp"
- imgDice4.Picture = LoadPicture(imageFile)
- End If
- If ckBox5.Value = False Then
- Range("F2").Value = Int(Rnd * 6) + 1
- imageFile = imagePath & Trim(Str(Range("F2").Value)) & ".bmp"
- imgDice5.Picture = LoadPicture(imageFile)
- End If
- If numRolls = 2 Then
- cmdRollDice.Enabled = False
- cmdNewGame.Enabled = True
- numRolls = 0
- Else
- ToggleControls True
- End If
- DisplayResult
- End Sub
- Private Sub DisplayResult()
- Dim numOnes As Integer
- Dim numTwos As Integer
- Dim numThrees As Integer
- Dim numFours As Integer
- Dim numFives As Integer
- Dim numSixes As Integer
- Dim result As String
- numOnes = GetNumOnes
- numTwos = GetNumTwos
- numThrees = GetNumThrees
- numFours = GetNumFours
- numFives = GetNumFives
- numSixes = GetNumSixes
- result = IsNothingOrStraight(numOnes, numTwos, numThrees, numFours, numFives, numSixes, result)
- result = IsOnePair(numOnes, numTwos, numThrees, numFours, numFives, numSixes, result)
- result = IsTwoPair(numOnes, numTwos, numThrees, numFours, numFives, numSixes, result)
- result = IsThreeOfAKind(numOnes, numTwos, numThrees, numFours, numFives, numSixes, result)
- result = IsFourOfAKind(numOnes, numTwos, numThrees, numFours, numFives, numSixes, result)
- result = IsFiveOfAKind(numOnes, numTwos, numThrees, numFours, numFives, numSixes, result)
- result = IsFullHouse(numOnes, numTwos, numThrees, numFours, numFives, numSixes, result)
- Range("C12").Value = result
- End Sub
- Private Function GetNumOnes() As Integer
- Dim numOnes As Integer
- If Range("B2").Value = 1 Then numOnes = numOnes + 1
- If Range("C2").Value = 1 Then numOnes = numOnes + 1
- If Range("D2").Value = 1 Then numOnes = numOnes + 1
- If Range("E2").Value = 1 Then numOnes = numOnes + 1
- If Range("F2").Value = 1 Then numOnes = numOnes + 1
- GetNumOnes = numOnes
- End Function
- Private Function GetNumTwos() As Integer
- Dim numTwos As Integer
- If Range("B2").Value = 2 Then numTwos = numTwos + 1
- If Range("C2").Value = 2 Then numTwos = numTwos + 1
- If Range("D2").Value = 2 Then numTwos = numTwos + 1
- If Range("E2").Value = 2 Then numTwos = numTwos + 1
- If Range("F2").Value = 2 Then numTwos = numTwos + 1
- GetNumTwos = numTwos
- End Function
- Private Function GetNumThrees() As Integer
- Dim numThrees As Integer
- If Range("B2").Value = 3 Then numThrees = numThrees + 1
- If Range("D2").Value = 3 Then numThrees = numThrees + 1
- If Range("E2").Value = 3 Then numThrees = numThrees + 1
- If Range("F2").Value = 3 Then numThrees = numThrees + 1
- GetNumThrees = numThrees
- End Function
- Private Function GetNumFours() As Integer
- Dim numFours As Integer
- If Range("B2").Value = 4 Then numFours = numFours + 1
- If Range("C2").Value = 4 Then numFours = numFours + 1
- If Range("D2").Value = 4 Then numFours = numFours + 1
- If Range("E2").Value = 4 Then numFours = numFours + 1
- If Range("F2").Value = 4 Then numFours = numFours + 1
- GetNumFours = numFours
- End Function
- Private Function GetNumFives() As Integer
- Dim numFives As Integer
- If Range("B2").Value = 5 Then numFives = numFives + 1
- If Range("C2").Value = 5 Then numFives = numFives + 1
- If Range("D2").Value = 5 Then numFives = numFives + 1
- If Range("E2").Value = 5 Then numFives = numFives + 1
- If Range("F2").Value = 5 Then numFives = numFives + 1
- GetNumFives = numFives
- End Function
- Private Function GetNumSixes() As Integer
- Dim numSixes As Integer
- If Range("B2").Value = 6 Then numSixes = numSixes + 1
- If Range("C2").Value = 6 Then numSixes = numSixes + 1
- If Range("D2").Value = 6 Then numSixes = numSixes + 1
- If Range("E2").Value = 6 Then numSixes = numSixes + 1
- If Range("F2").Value = 6 Then numSixes = numSixes + 1
- GetNumSixes = numSixes
- End Function
- Private Function IsNothingOrStraight(numOnes As Integer, numTwos As Integer, numThrees As Integer, numFours As Integer, numFives As Integer, numSixes As Integer, result As String) As String
- If (numOnes <= 1) And (numTwos <= 1) And (numThrees <= 1) And (numFours <= 1) And (numFives <= 1) And (numSixes <= 1) Then
- If (numSixes = 1) And (numOnes = 0) Then
- IsNothingOrStraight = "6 High Straight"
- ElseIf (numSixes = 1) And (numOnes = 1) Then
- IsNothingOrStraight = "6 High"
- Else
- IsNothingOrStraight = "5 High Straight"
- End If
- Else
- IsNothingOrStraight = result
- End If
- End Function
- Private Function IsOnePair(numOnes As Integer, numTwos As Integer, numThrees As Integer, numFours As Integer, numFives As Integer, numSixes As Integer, result As String) As String
- If (numOnes = 2) And (numTwos <= 1) And (numThrees <= 1) And (numFours <= 1) And (numFives <= 1) And (numSixes <= 1) Then
- IsOnePair = "Pair of Ones"
- ElseIf (numOnes <= 1) And (numTwos = 2) And (numThrees <= 1) And (numFours <= 1) And (numFives <= 1) And (numSixes <= 1) Then
- IsOnePair = "Pair of Twos"
- ElseIf (numOnes <= 1) And (numTwos <= 1) And (numThrees = 2) And (numFours <= 1) And (numFives <= 1) And (numSixes <= 1) Then
- IsOnePair = "Pair of Threes"
- ElseIf (numOnes <= 1) And (numTwos <= 1) And (numThrees <= 1) And (numFours = 2) And (numFives <= 1) And (numSixes <= 1) Then
- IsOnePair = "Pair of Fours"
- ElseIf (numOnes <= 1) And (numTwos <= 1) And (numThrees <= 1) And (numFours <= 1) And (numFives = 2) And (numSixes <= 1) Then
- IsOnePair = "Pair of Fives"
- ElseIf (numOnes <= 1) And (numTwos <= 1) And (numThrees <= 1) And (numFours <= 1) And (numFives <= 1) And (numSixes = 2) Then
- IsOnePair = "Pair of Sixes"
- Else
- IsOnePair = result
- End If
- End Function
- Private Function IsTwoPair(numOnes As Integer, numTwos As Integer, numThrees As Integer, numFours As Integer, numFives As Integer, numSixes As Integer, result As String) As String
- If (numOnes = 2 And numTwos = 2) Or (numOnes = 2 And numThrees = 2) Or (numOnes = 2 And numThrees = 2) Or (numOnes = 2 And numFours = 2) Or (numOnes = 2 And numFives = 2) Or (numOnes = 2 And numSixes = 2) Or (numTwos = 2 And numThrees = 2) Or (numTwos = 2 And numFours = 2) Or (numTwos = 2 And numFives = 2) Or (numTwos = 2 And numSixes = 2) Or (numThrees = 2 And numFours = 2) Or (numThrees = 2 And numFives = 2) Or (numThrees = 2 And numSixes = 2) Or (numFours = 2 And numFives = 2) Or (numFours = 2 And numSixes = 2) Or (numFives = 2 And numSixes = 2) Then
- IsTwoPair = "Two Pair"
- Else
- IsTwoPair = result
- End If
- End Function
- Private Function IsThreeOfAKind(numOnes As Integer, numTwos As Integer, numThrees As Integer, numFours As Integer, numFives As Integer, numSixes As Integer, result As String) As String
- If (numOnes = 3 And numTwos < 2 And numThrees < 2 And numFours < 2 And numFives < 2 And numSixes < 2) Then
- IsThreeOfAKind = "Three Ones"
- ElseIf (numOnes < 2 And numTwos = 3 And numThrees < 2 And numFours < 2 And numFives < 2 And numSixes < 2) Then
- IsThreeOfAKind = "Three Twos"
- ElseIf (numOnes < 2 And numTwos < 2 And numThrees = 3 And numFours < 2 And numFives < 2 And numSixes < 2) Then
- IsThreeOfAKind = "Three Threes"
- ElseIf (numOnes < 2 And numTwos < 2 And numThrees < 2 And numFours = 3 And numFives < 2 And numSixes < 2) Then
- IsThreeOfAKind = "Three Fours"
- ElseIf (numOnes < 2 And numTwos < 2 And numThrees < 2 And numFours < 2 And numFives = 3 And numSixes < 2) Then
- IsThreeOfAKind = "Three Fives"
- ElseIf (numOnes < 2 And numTwos < 2 And numThrees < 2 And numFours < 2 And numFives < 2 And numSixes = 3) Then
- IsThreeOfAKind = "Three Sixes"
- Else
- IsThreeOfAKind = result
- End If
- End Function
- Private Function IsFourOfAKind(numOnes As Integer, numTwos As Integer, numThrees As Integer, numFours As Integer, numFives As Integer, numSixes As Integer, result As String) As String
- If numOnes = 4 Then
- IsFourOfAKind = "Four Ones"
- ElseIf numTwos = 4 Then
- IsFourOfAKind = "Four Twos"
- ElseIf numThrees = 4 Then
- IsFourOfAKind = "Four Threes"
- ElseIf numFours = 4 Then
- IsFourOfAKind = "Four Fours"
- ElseIf numFives = 4 Then
- IsFourOfAKind = "Four Fives"
- ElseIf numSixes = 4 Then
- IsFourOfAKind = "Four Sixes"
- Else
- IsFourOfAKind = result
- End If
- End Function
- Private Function IsFiveOfAKind(numOnes As Integer, numTwos As Integer, numThrees As Integer, numFours As Integer, numFives As Integer, numSixes As Integer, result As String) As String
- If numOnes = 5 Then
- IsFiveOfAKind = "Five Ones"
- ElseIf numTwos = 5 Then
- IsFiveOfAKind = "Five Twos"
- ElseIf numThrees = 5 Then
- IsFiveOfAKind = "Five Threes"
- ElseIf numFours = 5 Then
- IsFiveOfAKind = "Five Fours"
- ElseIf numFives = 5 Then
- IsFiveOfAKind = "Five Fives"
- ElseIf numSixes = 5 Then
- IsFiveOfAKind = "Five Sixes"
- Else
- IsFiveOfAKind = result
- End If
- End Function
- Private Function IsFullHouse(numOnes As Integer, numTwos As Integer, numThrees As Integer, numFours As Integer, numFives As Integer, numSixes As Integer, result As String) As String
- If (numOnes = 3 And numTwos = 2) Or (numOnes = 3 And numThrees = 2) Or (numOnes = 3 And numFours = 2) Or (numOnes = 3 And numFives = 2) Or (numOnes = 3 And numSixes = 2) Or (numTwos = 3 And numOnes = 2) Or (numTwos = 3 And numThrees = 2) Or (numTwos = 3 And numFours = 2) Or (numTwos = 3 And numFives = 2) Or (numTwos = 3 And numSixes = 2) Or (numThrees = 3 And numOnes = 2) Or (numThrees = 3 And numTwos = 2) Or (numThrees = 3 And numFours = 2) Or (numThrees = 3 And numFives = 2) Or (numThrees = 3 And numSixes = 2) Or (numFours = 3 And numOnes = 2) Or (numFours = 3 And numTwos = 2) Or (numFours = 3 And numThrees = 2) Or (numFours = 3 And numFives = 2) Or (numFours = 3 And numSixes = 2) Or (numFives = 3 And numOnes = 2) Or (numFives = 3 And numTwos = 2) Or (numFives = 3 And numThrees = 2) Or (numFives = 3 And numFours = 2) Or (numFives = 3 And numSixes = 2) Or (numSixes = 3 And numOnes = 2) Or (numSixes = 3 And numTwos = 2) Or (numSixes = 3 And numThrees = 2) Or (numSixes = 3 And numFours = 2) Or ( _
- numSixes = 3 And numFives = 2) Then
- IsFullHouse = "Full House"
- Else
- IsFullHouse = result
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement