|
-
Dec 19th, 2007, 06:24 PM
#1
Thread Starter
New Member
Vba Excell
HEY guys
im doing my first year at university, doing business and i have a IT class. I was never good at it but i have an assignemnte that i must do using vba code( using the excel editor)
i have do do a project where i must have a table with all the poker sequences, picture of five cards. The cards must be shuffling and the sequences that appear must be counted on the table. So whilst the shuffling occures all the sequences that appear from each shuffle must be accounted. Any suggestion on the source vode to use?
many thanks
tesla
-
Dec 19th, 2007, 06:26 PM
#2
Re: Vba Excell
Thread moved from FAQ (Frequently Asked Questions) forum
-
Dec 19th, 2007, 10:20 PM
#3
Re: Vba Excell
 Originally Posted by tesla
HEY guys
im doing my first year at university, doing business and i have a IT class. I was never good at it but i have an assignemnte that i must do using vba code( using the excel editor)
i have do do a project where i must have a table with all the poker sequences, picture of five cards. The cards must be shuffling and the sequences that appear must be counted on the table. So whilst the shuffling occures all the sequences that appear from each shuffle must be accounted. Any suggestion on the source vode to use?
many thanks
tesla
Either your prof. is a sadist or I don't understand the problem. There are ~311 million possible 5 card hands, which would require around 4800 worksheets to display in Excel. That before the shuffling bit.
-
Dec 20th, 2007, 12:07 AM
#4
Re: Vba Excell
With a set of 52 cards, on doing suffling, we may have 52! = 8.06581751709439 * 10^67 different combinations.
From a set of 52 cards, you will have 52!/(5!*47!) = 2,598,960 different 5-card hands when the order of 5 cards does not matter.
If the order of cards is considered, you will have 52!/47! = 311,875,200 different 5-card hands.
-
Dec 20th, 2007, 06:37 AM
#5
Thread Starter
New Member
Re: Vba Excell
hey guys , sorry im from portugal my engish could have been a bit confusing , let me refrase i think i know what i said wrong
On the worksheet, make a button where it shuffles 52 cards and then shows the first 5. (i must creat a command button)
have a table that accounts any sequences that might have occured every time i had pressed the command button to shuffle.
-
Dec 20th, 2007, 06:46 AM
#6
Re: Vba Excell
Hi
Does this help?
This will generate any five numbers(between 0 and 53) in sheet1 in column A.
Simply place this code in a module and run it...
vb Code:
Sub RandNos()
Dim nums() As Integer
Dim maxval As Integer
Dim Ptr As Integer
Dim j As Integer, k As Integer
Randomize
'Number of cards in a pack
maxval = 52
ReDim nums(maxval, 2)
'Fill the initial array
For j = 1 To maxval
nums(j, 1) = j
nums(j, 2) = Int((Rnd * maxval) + 1)
Next j
'Sort the array based on the random numbers
For j = 1 To maxval - 1
Ptr = j
For k = j + 1 To maxval
If nums(Ptr, 2) > nums(k, 2) Then Ptr = k
Next k
If Ptr <> j Then
k = nums(Ptr, 1)
nums(Ptr, 1) = nums(j, 1)
nums(j, 1) = k
k = nums(Ptr, 2)
nums(Ptr, 2) = nums(j, 2)
nums(j, 2) = k
End If
Next j
'Fill in the cells
Ptr = 0
'Display any five number in sheet1 in column A
For k = 1 To 5
Ptr = Ptr + 1
Sheets("Sheet1").Range("A" & k) = nums(Ptr, 1)
Next k
End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Dec 20th, 2007, 05:00 PM
#7
Thread Starter
New Member
Re: Vba Excell
hi, thats more a less but i must generatet "5 cards" everytime i press the command button and then account any sequence from that shuffle into a table(if it is a valid poker seuqence , of any kind, fullhouse pair, etc)
thank you.. for all the help u guys are giving me!.. i was never good at programming
Last edited by tesla; Dec 20th, 2007 at 05:10 PM.
-
Dec 20th, 2007, 05:08 PM
#8
Thread Starter
New Member
Re: Vba Excell
also on the code u gave me.. don't i have to start the beggining with Private Sub.. its giving me error
-
Dec 20th, 2007, 07:24 PM
#9
Re: Vba Excell
Hi Two things...
but i must generatet "5 cards" everytime i press the command button and then account any sequence from that shuffle into a table(if it is a valid poker seuqence , of any kind, fullhouse pair, etc)
1) Do you want 5 cards to be displayed using animation on excel sheet?
also on the code u gave me.. don't i have to start the beggining with Private Sub.. its giving me error
2) the code needs to placed in the click event of the command button. something like...
vb Code:
Private Sub CommandButton1_Click()
'the above code here... minus the Sub RandNos() and End Sub
End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Dec 21st, 2007, 06:34 AM
#10
Thread Starter
New Member
Re: Vba Excell
1) Do you want 5 cards to be displayed using animation on excel sheet?
yep! exactly i need five cards to appear. so every time i press a button five random cards appear and if they are a poker sequence it must be accounted on a table from everytime that sequence appears like
fullhouse 6
double pair 5
........ and the rest of the valid poker sequences
thanking in advance
tesla
-
Dec 24th, 2007, 08:41 AM
#11
Hyperactive Member
Re: Vba Excell
Do you also want the poker rules be implemented on it? Swap n cards, etc..
or just a button that simply displays 5 numbers on an excel row?
-
Dec 24th, 2007, 11:53 AM
#12
Thread Starter
New Member
Re: Vba Excell
or just a button that simply displays 5 numbers on an excel row?
yep but i want 5cards not numbers
-
Dec 24th, 2007, 01:25 PM
#13
-
Dec 24th, 2007, 01:45 PM
#14
Hyperactive Member
Re: Vba Excell
I havent done VB for 6 years but i think this should at least help you for a start
Code:
Option Explicit
Private Sub CommandButton1_Click()
'create array of cards
Dim cards(0 To 51) As String
'add items to array
cards(0) = "C_A"
cards(1) = "C_2"
cards(2) = "C_3"
cards(3) = "C_4"
cards(4) = "C_5"
cards(5) = "C_6"
cards(6) = "C_7"
cards(7) = "C_8"
cards(8) = "C_9"
cards(9) = "C_10"
cards(10) = "C_Jack"
cards(11) = "C_Queen"
cards(12) = "C_King"
cards(13) = "H_A"
cards(14) = "H_2"
cards(15) = "H_3"
cards(16) = "H_4"
cards(17) = "H_5"
cards(18) = "H_6"
cards(19) = "H_7"
cards(20) = "H_8"
cards(21) = "H_9"
cards(22) = "H_10"
cards(23) = "H_Jack"
cards(24) = "H_Queen"
cards(25) = "H_King"
cards(26) = "D_A"
cards(27) = "D_2"
cards(28) = "D_3"
cards(29) = "D_4"
cards(30) = "D_5"
cards(31) = "D_6"
cards(32) = "D_7"
cards(33) = "D_8"
cards(34) = "D_9"
cards(35) = "D_10"
cards(36) = "D_Jack"
cards(37) = "D_Queen"
cards(38) = "D_King"
cards(39) = "S_A"
cards(40) = "S_2"
cards(41) = "S_3"
cards(42) = "S_4"
cards(43) = "S_5"
cards(44) = "S_6"
cards(45) = "S_7"
cards(46) = "S_8"
cards(47) = "S_9"
cards(48) = "S_10"
cards(49) = "S_Jack"
cards(50) = "S_Queen"
cards(51) = "S_King"
Dim x As Integer
Dim ShuffledCard(0 To 51) As String
Dim temp As Integer
'shuffle cards
For x = 52 To 1 Step -1
Randomize
temp = Int(Rnd() * x)
ShuffledCard(x - 1) = cards(temp)
cards(temp) = cards(x - 1)
Next
Dim k As Integer
For k = 1 To 52
Sheet1.Range("A" & k) = ShuffledCard(k - 1)
Next k
'add the poker rules here
End Sub
This should help you at least shuffle the cards and display the shuffled cards into the excel sheet. S = Spade, D = Diamond, H = Hearts, C = Club, K = king, Q = Queen and J = Jack
You can easily alter this code if you want to replace the name to a picture.
Last edited by Greyskull; Dec 24th, 2007 at 06:06 PM.
-
Dec 25th, 2007, 08:08 AM
#15
Thread Starter
New Member
Re: Vba Excell
MANY THANKS, AND HAPPY CHRISTMAS FOR ALL OF YOU PEOPLE THAT ARE HELPING ME!!!
for the accounting of the sequences these are the ones i must do... any ideas? (and thanking again for all the help!)
maximum sequence : 5consecutive cards from the same suite including the ace
Minimum sequence : Five consecutive cards from the same suite
Poker : 4equal cards
Full house : 3equalcards +2equal cards
colour : 5cards from the same suite
Sequence : 5consecutive cards from any suite
Trio : three equal cards
2pair : 2eual cards + 2equal cards
-
Dec 25th, 2007, 04:40 PM
#16
Hyperactive Member
Re: Vba Excell
Four of the same cards
Pair
Regards
-
Dec 26th, 2007, 05:59 AM
#17
Thread Starter
New Member
Re: Vba Excell
Four of the same cards
Pair
don't need to do those!! only the ones from the list
-
Jan 7th, 2008, 07:13 PM
#18
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|