UserForm Textbox

Stromma

Board Regular
Joined
Feb 8, 2004
Messages
240
Hi All

2 years ago i created a YatzY in excel for my kids to play with. It uses random numbers in textboxes and then they enter their score through an inputbox before it is saved to the sheet. They played with it for a while but got bored since it allows "some people" to cheat when they enter their score.

I never intended to take this any further but last satarday one of my sons got hurt real bad in an accident and is now tied to the bed for the rest of summer, and now he wonders if i can do something to make this more fun.

So now i'm trying to change this so that it put's the relevant score by pushing a button. I have managed to work this out for 1 to 6, Chance & Yatzy. The setup looks like:

Textbox2 to textbox7 = randome numbers and textbox1 = Score

It's 12 different subs i need help with:

1 Pair: Check if thers are 1 or maybe more pars in txt2 to 7 and sum the highest to txt1.

2Pair: Check to se if their are 2 ore more pairs and sum the 2 highest to txt1

3Pairs: Check to se if their are 3 pairs and sum to txt1

3 of a kind: Check for 3 of a kind, and as it possible to get 2*3 sum the highest to txt1

4 and 5 of a kind: Check for 4/5 of a kind, and sum the highest to txt1

Straight: 3 diffent. 1 to 5, 2 to 6 and 1 to 6. Sum for 1 to 5 = 15, 2 to 6 = 20 and 1 to 6 = 21

I'm not sure of which name these 3 have in english but the setup is:
3+2 ex 3 kings & 2 Ace

3+3 ex 3 kings & 3 Ace

4+2 ex 4 kings & 2 Ace

I hope you get the picture...

Anyway, this is not something that absolutely need to be solved but all help will be highly appreciated

/Roger S
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Bump!

I guess i need to loop through all textboxes (2 to 7) and compare them, and i can honestly say that i'm not very good at this...

Anyone who have an idea of where to begin?

/Roger
 
Upvote 0
Hi Stromma, Im sorry to hear your son is not well. Hopefully he will be better soon.

I quite like Yahtzee too (Yacht for those US people) and play it every now and then. Theres a fair # variables with this so I can help you if you want but I had a quick look on Google with the keywords "Excel Games" and there are quite a few hits.

Theres heaps on this page here including Yahtee...

http://www.xl-logic.com/pages/games.html

regards
parry
 
Upvote 0
Hi Parry & Thanks for your reply!

Regarding to my son, 0.2 cm deeper and he would have died, now he will be fully recovered, so if i never ever win on a lottery again i'm not gonna complain...

I knew that this was much to ask for, and yes their are games available for download...

But:
"My Game" allows 6 people to play against each other at the same time, save the highscore's, prints a winner trophy, plays a winner song etc.
The main thing really is that they can play more than one at the time.

I did't expect somebody to come up with a solution for the whole problem (the 12 sub's is actually * 6 players with different sheets etc), but some suggestions on how to go would be nice. The main problems are 4:

1. Loop through txt 2 - 6, se if there are duplicates and group the values so i can count points (ex if their are 3 pairs assign them to ex value a, b, c)

2. If there are, does they meet the criteria (ex 1+1, 2+3, 3+3 etc)

3. If there are ex pairs assigned to a, b, c, check a, b, c for the highest value

4. Assign matches to ex f for counting the score. If there are 3 pair assigned to a, b, c, and b is highest set f = b, if there are 2+3 assigned to a + b set f = a + b

There's no hurry and as i said, any suggestions would be highly appreciated!

/Roger
 
Upvote 0
Hi Roger, I believe you need to store values for each of the possible outcomes (1-6,3 of a kind, straight etc) and i have done the following code based on textboxes for each of these outcomes, plus textboxes for each of the 5 dice. All textboxes have txt in front. Perhaps this will help you...

Code:
Private Sub CommandButton1_Click()
Dim DiceVals As String, Die1 As Integer, Die2 As Integer, Die3 As Integer, Die4 As Integer
Dim Die5 As Integer, Die6 As Integer

'Roll ye olde dice
Call DiceRoll

'Create an array (of sorts) holding the dice values
DiceVals = "{" & txtDice1 & "," & txtDice2 & "," & txtDice3 & "," & txtDice4 & "," & txtDice5 & "}"

'Determine total of each die
Die1 = Evaluate("SUM(IF(" & DiceVals & "=1,1,0))")
Die2 = Evaluate("SUM(IF(" & DiceVals & "=2,1,0))")
Die3 = Evaluate("SUM(IF(" & DiceVals & "=3,1,0))")
Die4 = Evaluate("SUM(IF(" & DiceVals & "=4,1,0))")
Die5 = Evaluate("SUM(IF(" & DiceVals & "=5,1,0))")
Die6 = Evaluate("SUM(IF(" & DiceVals & "=6,1,0))")

'Total of single values 1 to 6 multiplied by its die number
txtOne = Die1
txtTwo = Die2 * 2
txtThree = Die3 * 3
txtFour = Die4 * 4
txtFive = Die5 * 5
txtSix = Die6 * 6

'Total for 3 of a Kind. If 3 or more dice are the same then total all 5 dice
If Evaluate("MAX(FREQUENCY(" & DiceVals & ",{1,2,3,4,5,6}))") >= 3 Then
txt3ofakind = Evaluate("Sum(" & DiceVals & ")")
Else
txt3ofakind = 0
End If

'Total for 4 of a Kind. If 4 or more dice are the same then total all 5 dice
If Evaluate("MAX(FREQUENCY(" & DiceVals & ",{1,2,3,4,5,6}))") >= 4 Then
txt4ofakind = Evaluate("Sum(" & DiceVals & ")")
Else
txt4ofakind = 0
End If

'Total for a Full House
If Evaluate("MAX(FREQUENCY(" & DiceVals & ",{1,2,3,4,5,6}))") = 3 Then
    If Die1 = 2 Or Die2 = 2 Or Die3 = 2 Or Die4 = 2 Or Die5 = 2 Or Die6 = 2 Then
    txtFullHouse = 25
    Else
    txtFullHouse = 0
    End If
Else
txtFullHouse = 0
End If

'Total of Small Straight. Any 4 dice in sequence. eg 1,2,3,4 or 3,4,5,6 etc
If Die1 > 0 And Die2 > 0 And Die3 > 0 And Die4 > 0 Or _
    Die2 > 0 And Die3 > 0 And Die4 > 0 And Die5 > 0 Or _
    Die3 > 0 And Die4 > 0 And Die5 > 0 And Die6 > 0 Then
txtSmallStraight = 30
Else
txtSmallStraight = 0
End If

'Total of Large Straight. Any 5 dice in sequence. eg 1,2,3,4,5 or 2,3,4,5,6
If Die1 > 0 And Die2 > 0 And Die3 > 0 And Die4 > 0 And Die5 > 0 Or _
    Die2 > 0 And Die3 > 0 And Die4 > 0 And Die5 > 0 And Die6 > 0 Then
txtLargeStraight = 40
Else
txtLargeStraight = 0
End If

'Total for Chance
txtChance = Evaluate("Sum(" & DiceVals & ")")

'Total for Yahtzee
If Evaluate("MAX(FREQUENCY(" & DiceVals & ",{1,2,3,4,5,6}))") = 5 Then
txtYahtzee = 50
Else
txtYahtzee = 0
End If

End Sub


Sub DiceRoll()
'You would need to change this to account for holding dice
txtDice1 = Int(6 * Rnd + 1)
txtDice2 = Int(6 * Rnd + 1)
txtDice3 = Int(6 * Rnd + 1)
txtDice4 = Int(6 * Rnd + 1)
txtDice5 = Int(6 * Rnd + 1)
End Sub

regards
parry.
 
Upvote 0
Hi Parry

A big Thanks for your reply, i really appreciate it!

First: I need the number of dice to be 6, and when i try to make it count with 6 it doesn't work.

txtOne To Six works fine!

Three of a kind (and four of a kind) works (with 5 dice's), but they should only sum the three of a kind (or four of a kind), as for now it sums all dice's.

Ex: Now if i got 1, 2, 2, 1, 2 sum = 8 should be = 6

With 6 dice's, since their can be 2 pair of matches for three of a kind, it shold count highest match.

I also need to check for 5 of a kind.

Small straight should be: 1, 2, 3, 4, 5 = points 15 = Sum 1, 2, 3, 4, 5
Large straight should be: 2, 3, 4, 5, 6 = points 20 = Sum 2, 3, 4, 5, 6
Full straight should be: 1, 2, 3, 4, 5, 6 = points 21 = Sum 1, 2, 3, 4, 5, 6 = all dice's

House = 3 + 2 sum = points for the 3 + 2 dice's that match
Ex: 3, 3, 3 + 2, 2 + 1 = points 13 = no count of nr 1

In this game (in Seden called MaxiYatzy) it also counts
Full House = 3 + 3 = points sum all dice's
Tower = 4 + 2 = points sum all dice's

I also need to check pairs.
One pair = sum the highest pair (could be 3 possible matches) count the highest.
Two pairs = Sum dice's in pair one & two = could be three pairs and then it should sum the the two highest
Three pairs = Sum all Dice's

Once again, a big Thanks for your time and effort!
And if i ever comes to Wellington, New Zealand, the (y) are on me...


/Roger
 
Upvote 0
Hi Roger, I think there may be several variations of the rules as Ive seen games that have 5 dice and others with 6 and the points differ as well as evidenced between the code above and what you wanted. The logic of totalling the number of each die first, putting this into an array and then using the array as a basis to calculate your points is still the way to go IMHO. You will need to post what the rules are for each category so I can understand how you are calculating them.

As you can see by my code I have used the Evaluate method which is just using a formula in code. So what you need to do is work out what the formula is and then this can be converted to code. Some things like the straight I wasnt sure how to do in a single formula so I worked it out a manual way. Its not essential to use formulas but it makes the code shorter and less complicated.

So for the formulas, I suggest posting a separate topic explaining you have an array of 6 numbers in no particular order (give an example like {1,4,2,5,4,4} ) and ask what formula you will need to calculate x or y. Hopefully one of the gurus like Aladdin may be able to give a cracking solution.

I had a go of creating a Yahtzee form myself although just for single players at this point. Send me a PM with your email address and I will forward the book to you. The calculations will be a bit different but the methodology may be useful to you in your version.
 
Upvote 0
Hi All

I just make this post to say that the problem now is solved thanks to Parry, who has been a real star, providing everything from formula example's to testbooks and a final solution!

I knew that i was asking the world, and i really didn't expect anyone to answer my post, but once again i was wrong...

With respect for the time and effort Parry has made on this i won't provide the solution here. Let's just say that if anyone else is having a problem similar to this, i'll know who to ask...

Thanks Parry!

/Roger
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,234
Members
449,092
Latest member
SCleaveland

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top