Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 105
Default Displaying possible combinations

Hi everyone,

I was researching on how to display possible poker hands (5 cards)
using a VBA. I found this code within this group. However as you can
see, this code below does ignore the suits. Is it possible to alter
this code to display different possible poker hands including the
suits?

Thank you very much.

where;
1. Diamond = "D"
2. Heart = "H"
3. Spade = "S"
4. Clover = "C"
'Ace' being = 1, 'King' being = 13



Sub poker_hand2()

Dim card1, card2, card3, card4, card5 As Integer


For card1 = 1 To 13
For card2 = card1 To 13
For card3 = card2 To 13
For card4 = card3 To 13
For card5 = card4 To 13
If Not (card1 = card2 And card2 = card3 And
card3 =
card4 And card4 = card5) Then
ActiveCell = card1 & "-" & card2 & "-" &
card3 &
"-" & card4 & "-" & card5
If ActiveCell.Row = 65536 Then
ActiveCell.Offset(-65535, 1).Select
Else
ActiveCell.Offset(1, 0).Select
End If
End If
Next card5
Next card4
Next card3
Next card2
Next card1


End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Displaying possible combinations

Hi
Try this.

Sub poker_hand2()


Dim card1 As Integer, card2 As Integer, card3 As Integer, card4 As
Integer, card5 As Integer
Application.ScreenUpdating = False

For card1 = 1 To 52
For card2 = card1 To 52
For card3 = card2 To 52
For card4 = card3 To 52
For card5 = card4 To 52
If Not (card1 = card2 And card2 = card3 And
card3 = card4 And card4 = card5) Then
ActiveCell = Card(card1) & "-" &
Card(card2) & "-" & Card(card3) & "-" & Card(card4) & "-" &
Card(card5)
If ActiveCell.Row = 65536 Then
ActiveCell.Offset(-65535, 1).Select
Else
ActiveCell.Offset(1, 0).Select
End If
End If
Next card5
Next card4
Next card3
Next card2
Next card1


End Sub

Function Card(x As Integer) As String
Select Case x
Case Is <= 13: Card = x & "D"
Case Is <= 26: Card = x & "H"
Case Is <= 39: Card = x & "S"
Case Else: Card = x & "C"
End Select
End Function

As usual, careful with the line wrapping. Also note that
Dim card 1, card2 as integer

makes Card2 an integer but Card1 a variant. What you mean is
Dim card 1 as integer, card2 as integer

If you don't do this, you will get an error calling the function Card.
regards
Paul

On Jun 23, 8:11*am, James8309 wrote:
Hi everyone,

I was researching on how to display possible poker hands (5 cards)
using a VBA. I found this code within this group. However as you can
see, this code below does ignore the suits. Is it possible to alter
this code to display different possible poker hands including the
suits?

Thank you very much.

where;
1. Diamond = "D"
2. Heart = "H"
3. Spade = "S"
4. Clover = "C"
'Ace' being = 1, 'King' being = 13

Sub poker_hand2()

Dim card1, card2, card3, card4, card5 As Integer

* * For card1 = 1 To 13
* * * * For card2 = card1 To 13
* * * * * * For card3 = card2 To 13
* * * * * * * * For card4 = card3 To 13
* * * * * * * * * * For card5 = card4 To 13
* * * * * * * * * * * * If Not (card1 = card2 And card2 = card3 And
card3 =
card4 And card4 = card5) Then
* * * * * * * * * * * * * * ActiveCell = card1 & "-" & card2 & "-" &
card3 &
"-" & card4 & "-" & card5
* * * * * * * * * * * * * * If ActiveCell.Row = 65536 Then
* * * * * * * * * * * * * * * * ActiveCell.Offset(-65535, 1).Select
* * * * * * * * * * * * * * Else
* * * * * * * * * * * * * * * * ActiveCell.Offset(1, 0).Select
* * * * * * * * * * * * * * End If
* * * * * * * * * * * * End If
* * * * * * * * * * Next card5
* * * * * * * * Next card4
* * * * * * Next card3
* * * * Next card2
* * Next card1

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 105
Default Displaying possible combinations

On Jun 23, 6:34*pm, wrote:
Hi
Try this.

Sub poker_hand2()

Dim card1 As Integer, card2 As Integer, card3 As Integer, card4 As
Integer, card5 As Integer
Application.ScreenUpdating = False

* * For card1 = 1 To 52
* * * * For card2 = card1 To 52
* * * * * * For card3 = card2 To 52
* * * * * * * * For card4 = card3 To 52
* * * * * * * * * * For card5 = card4 To 52
* * * * * * * * * * * * If Not (card1 = card2 And card2 = card3 And
card3 = card4 And card4 = card5) Then
* * * * * * * * * * * * * * ActiveCell = Card(card1) & "-" &
Card(card2) & "-" & Card(card3) & "-" & Card(card4) & "-" &
Card(card5)
* * * * * * * * * * * * * * If ActiveCell.Row = 65536 Then
* * * * * * * * * * * * * * * * ActiveCell.Offset(-65535, 1).Select
* * * * * * * * * * * * * * Else
* * * * * * * * * * * * * * * * ActiveCell.Offset(1, 0).Select
* * * * * * * * * * * * * * End If
* * * * * * * * * * * * End If
* * * * * * * * * * Next card5
* * * * * * * * Next card4
* * * * * * Next card3
* * * * Next card2
* * Next card1

End Sub

Function Card(x As Integer) As String
Select Case x
* * Case Is <= 13: Card = x & "D"
* * Case Is <= 26: Card = x & "H"
* * Case Is <= 39: Card = x & "S"
* * Case Else: Card = x & "C"
End Select
End Function

As usual, careful with the line wrapping. Also note that
Dim card 1, card2 as integer

makes Card2 an integer but Card1 a variant. What you mean is
Dim card 1 as integer, card2 as integer

If you don't do this, you will get an error calling the function Card.
regards
Paul

On Jun 23, 8:11*am, James8309 wrote:



Hi everyone,


I was researching on how to display possiblepokerhands (5 cards)
using a VBA. I found this code within this group. However as you can
see, this code below does ignore the suits. Is it possible to alter
this code to display different possiblepokerhands including the
suits?


Thank you very much.


where;
1. Diamond = "D"
2. Heart = "H"
3. Spade = "S"
4. Clover = "C"
'Ace' being = 1, 'King' being = 13


Sub poker_hand2()


Dim card1, card2, card3, card4, card5 As Integer


* * For card1 = 1 To 13
* * * * For card2 = card1 To 13
* * * * * * For card3 = card2 To 13
* * * * * * * * For card4 = card3 To 13
* * * * * * * * * * For card5 = card4 To 13
* * * * * * * * * * * * If Not (card1 = card2 And card2 = card3 And
card3 =
card4 And card4 = card5) Then
* * * * * * * * * * * * * * ActiveCell = card1 & "-" & card2 & "-" &
card3 &
"-" & card4 & "-" & card5
* * * * * * * * * * * * * * If ActiveCell.Row = 65536 Then
* * * * * * * * * * * * * * * * ActiveCell.Offset(-65535, 1).Select
* * * * * * * * * * * * * * Else
* * * * * * * * * * * * * * * * ActiveCell.Offset(1, 0).Select
* * * * * * * * * * * * * * End If
* * * * * * * * * * * * End If
* * * * * * * * * * Next card5
* * * * * * * * Next card4
* * * * * * Next card3
* * * * Next card2
* * Next card1


End Sub- Hide quoted text -


- Show quoted text -


Thanks mate. You are a champ.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Displaying possible combinations

Hi
Just to finish the thread with the error you noticed. The Card
function should be

Function Card(x As Integer) As String
Select Case x
Case Is <= 13: Card = x & "D"
Case Is <= 26: Card = x-13 & "H"
Case Is <= 39: Card = x-26 & "S"
Case Else: Card = x-39 & "C"
End Select
End Function

or cards are numbered 1 to 52 instead of four suits of 1 to 13.

regards
Paul

On Jun 24, 12:27*am, James8309 wrote:
On Jun 23, 6:34*pm, wrote:





Hi
Try this.


Sub poker_hand2()


Dim card1 As Integer, card2 As Integer, card3 As Integer, card4 As
Integer, card5 As Integer
Application.ScreenUpdating = False


* * For card1 = 1 To 52
* * * * For card2 = card1 To 52
* * * * * * For card3 = card2 To 52
* * * * * * * * For card4 = card3 To 52
* * * * * * * * * * For card5 = card4 To 52
* * * * * * * * * * * * If Not (card1 = card2 And card2 = card3 And
card3 = card4 And card4 = card5) Then
* * * * * * * * * * * * * * ActiveCell = Card(card1) & "-" &
Card(card2) & "-" & Card(card3) & "-" & Card(card4) & "-" &
Card(card5)
* * * * * * * * * * * * * * If ActiveCell.Row = 65536 Then
* * * * * * * * * * * * * * * * ActiveCell.Offset(-65535, 1).Select
* * * * * * * * * * * * * * Else
* * * * * * * * * * * * * * * * ActiveCell.Offset(1, 0).Select
* * * * * * * * * * * * * * End If
* * * * * * * * * * * * End If
* * * * * * * * * * Next card5
* * * * * * * * Next card4
* * * * * * Next card3
* * * * Next card2
* * Next card1


End Sub


Function Card(x As Integer) As String
Select Case x
* * Case Is <= 13: Card = x & "D"
* * Case Is <= 26: Card = x & "H"
* * Case Is <= 39: Card = x & "S"
* * Case Else: Card = x & "C"
End Select
End Function


As usual, careful with the line wrapping. Also note that
Dim card 1, card2 as integer


makes Card2 an integer but Card1 a variant. What you mean is
Dim card 1 as integer, card2 as integer


If you don't do this, you will get an error calling the function Card.
regards
Paul


On Jun 23, 8:11*am, James8309 wrote:


Hi everyone,


I was researching on how to display possiblepokerhands (5 cards)
using a VBA. I found this code within this group. However as you can
see, this code below does ignore the suits. Is it possible to alter
this code to display different possiblepokerhands including the
suits?


Thank you very much.


where;
1. Diamond = "D"
2. Heart = "H"
3. Spade = "S"
4. Clover = "C"
'Ace' being = 1, 'King' being = 13


Sub poker_hand2()


Dim card1, card2, card3, card4, card5 As Integer


* * For card1 = 1 To 13
* * * * For card2 = card1 To 13
* * * * * * For card3 = card2 To 13
* * * * * * * * For card4 = card3 To 13
* * * * * * * * * * For card5 = card4 To 13
* * * * * * * * * * * * If Not (card1 = card2 And card2 = card3 And
card3 =
card4 And card4 = card5) Then
* * * * * * * * * * * * * * ActiveCell = card1 & "-" & card2 & "-" &
card3 &
"-" & card4 & "-" & card5
* * * * * * * * * * * * * * If ActiveCell..Row = 65536 Then
* * * * * * * * * * * * * * * * ActiveCell.Offset(-65535, 1).Select
* * * * * * * * * * * * * * Else
* * * * * * * * * * * * * * * * ActiveCell.Offset(1, 0).Select
* * * * * * * * * * * * * * End If
* * * * * * * * * * * * End If
* * * * * * * * * * Next card5
* * * * * * * * Next card4
* * * * * * Next card3
* * * * Next card2
* * Next card1


End Sub- Hide quoted text -


- Show quoted text -


Thanks mate. You are a champ.- Hide quoted text -

- Show quoted text -


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 105
Default Displaying possible combinations

On 6¿ù24ÀÏ, ¿ÀÈÄ6½Ã39ºÐ, wrote:
Hi
Just to finish the thread with the error you noticed. The Card
function should be

Function Card(x As Integer) As String
Select Case x
Case Is <= 13: Card = x & "D"
Case Is <= 26: Card = x-13 & "H"
Case Is <= 39: Card = x-26 & "S"
Case Else: Card = x-39 & "C"
End Select
End Function

or cards are numbered 1 to 52 instead of four suits of 1 to 13.

regards
Paul

On Jun 24, 12:27 am, James8309 wrote:



On Jun 23, 6:34 pm, wrote:


Hi
Try this.


Sub poker_hand2()


Dim card1 As Integer, card2 As Integer, card3 As Integer, card4 As
Integer, card5 As Integer
Application.ScreenUpdating = False


For card1 = 1 To 52
For card2 = card1 To 52
For card3 = card2 To 52
For card4 = card3 To 52
For card5 = card4 To 52
If Not (card1 = card2 And card2 = card3 And
card3 = card4 And card4 = card5) Then
ActiveCell = Card(card1) & "-" &
Card(card2) & "-" & Card(card3) & "-" & Card(card4) & "-" &
Card(card5)
If ActiveCell.Row = 65536 Then
ActiveCell.Offset(-65535, 1).Select
Else
ActiveCell.Offset(1, 0).Select
End If
End If
Next card5
Next card4
Next card3
Next card2
Next card1


End Sub


Function Card(x As Integer) As String
Select Case x
Case Is <= 13: Card = x & "D"
Case Is <= 26: Card = x & "H"
Case Is <= 39: Card = x & "S"
Case Else: Card = x & "C"
End Select
End Function


As usual, careful with the line wrapping. Also note that
Dim card 1, card2 as integer


makes Card2 an integer but Card1 a variant. What you mean is
Dim card 1 as integer, card2 as integer


If you don't do this, you will get an error calling the function Card..
regards
Paul


On Jun 23, 8:11 am, James8309 wrote:


Hi everyone,


I was researching on how to display possiblepokerhands (5 cards)
using a VBA. I found this code within this group. However as you can
see, this code below does ignore the suits. Is it possible to alter
this code to display different possiblepokerhands including the
suits?


Thank you very much.


where;
1. Diamond = "D"
2. Heart = "H"
3. Spade = "S"
4. Clover = "C"
'Ace' being = 1, 'King' being = 13


Sub poker_hand2()


Dim card1, card2, card3, card4, card5 As Integer


For card1 = 1 To 13
For card2 = card1 To 13
For card3 = card2 To 13
For card4 = card3 To 13
For card5 = card4 To 13
If Not (card1 = card2 And card2 = card3 And
card3 =
card4 And card4 = card5) Then
ActiveCell = card1 & "-" & card2 & "-" &
card3 &
"-" & card4 & "-" & card5
If ActiveCell.Row = 65536 Then
ActiveCell.Offset(-65535, 1).Select
Else
ActiveCell.Offset(1, 0).Select
End If
End If
Next card5
Next card4
Next card3
Next card2
Next card1


End Sub- Hide quoted text -


- Show quoted text -


Thanks mate. You are a champ.- Hide quoted text -


- Show quoted text -- µû¿Â ÅØ½ºÆ® ¼û±± -


- µû¿Â ÅØ½ºÆ® º¸± -


Really really smart they way you added Function. :D

It works beautifully! except that 5 card combinations have some
unrealistic combos where more than 1 same card is within those 5 cards
i.e. 1D-1D-1D-1D-1D

I tried thinking how I can prevent or delete those combination where
there are more than 1 same card but it is surely proving difficulties
lol.

I owe you a big steak!!

Have a good night mate.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Displaying possible combinations

Hi
This was taken care of originally in the line
If Not (card1 = card2 And card2 = card3 And
card3 = card4 And card4 = card5) Then

when there were 13 cards, but does not work for 52 as cards 1 and 14
(say) are both card 1 of two different suits. Replace all the

card1 = card2 bits

with

Card(Card1) = Card(card2)

to catch the card number and suit and, fingers crossed, things should
now work.
regards
Paul

On Jun 24, 10:52 am, James8309 wrote:
On 6¿ù24ÀÏ, ¿ÀÈÄ6½Ã39ºÐ, wrote:





Hi
Just to finish the thread with the error you noticed. The Card
function should be


Function Card(x As Integer) As String
Select Case x
Case Is <= 13: Card = x & "D"
Case Is <= 26: Card = x-13 & "H"
Case Is <= 39: Card = x-26 & "S"
Case Else: Card = x-39 & "C"
End Select
End Function


or cards are numbered 1 to 52 instead of four suits of 1 to 13.


regards
Paul


On Jun 24, 12:27 am, James8309 wrote:


On Jun 23, 6:34 pm, wrote:


Hi
Try this.


Sub poker_hand2()


Dim card1 As Integer, card2 As Integer, card3 As Integer, card4 As
Integer, card5 As Integer
Application.ScreenUpdating = False


For card1 = 1 To 52
For card2 = card1 To 52
For card3 = card2 To 52
For card4 = card3 To 52
For card5 = card4 To 52
If Not (card1 = card2 And card2 = card3 And
card3 = card4 And card4 = card5) Then
ActiveCell = Card(card1) & "-" &
Card(card2) & "-" & Card(card3) & "-" & Card(card4) & "-" &
Card(card5)
If ActiveCell.Row = 65536 Then
ActiveCell.Offset(-65535, 1).Select
Else
ActiveCell.Offset(1, 0).Select
End If
End If
Next card5
Next card4
Next card3
Next card2
Next card1


End Sub


Function Card(x As Integer) As String
Select Case x
Case Is <= 13: Card = x & "D"
Case Is <= 26: Card = x & "H"
Case Is <= 39: Card = x & "S"
Case Else: Card = x & "C"
End Select
End Function


As usual, careful with the line wrapping. Also note that
Dim card 1, card2 as integer


makes Card2 an integer but Card1 a variant. What you mean is
Dim card 1 as integer, card2 as integer


If you don't do this, you will get an error calling the function Card.
regards
Paul


On Jun 23, 8:11 am, James8309 wrote:


Hi everyone,


I was researching on how to display possiblepokerhands (5 cards)
using a VBA. I found this code within this group. However as you can
see, this code below does ignore the suits. Is it possible to alter
this code to display different possiblepokerhands including the
suits?


Thank you very much.


where;
1. Diamond = "D"
2. Heart = "H"
3. Spade = "S"
4. Clover = "C"
'Ace' being = 1, 'King' being = 13


Sub poker_hand2()


Dim card1, card2, card3, card4, card5 As Integer


For card1 = 1 To 13
For card2 = card1 To 13
For card3 = card2 To 13
For card4 = card3 To 13
For card5 = card4 To 13
If Not (card1 = card2 And card2 = card3 And
card3 =
card4 And card4 = card5) Then
ActiveCell = card1 & "-" & card2 & "-" &
card3 &
"-" & card4 & "-" & card5
If ActiveCell.Row = 65536 Then
ActiveCell.Offset(-65535, 1).Select
Else
ActiveCell.Offset(1, 0).Select
End If
End If
Next card5
Next card4
Next card3
Next card2
Next card1


End Sub- Hide quoted text -


- Show quoted text -


Thanks mate. You are a champ.- Hide quoted text -


- Show quoted text -- µû¿Â ÅØ½ºÆ® ¼û±± -


- µû¿Â ÅØ½ºÆ® º¸± -


Really really smart they way you added Function. :D

It works beautifully! except that 5 card combinations have some
unrealistic combos where more than 1 same card is within those 5 cards
i.e. 1D-1D-1D-1D-1D

I tried thinking how I can prevent or delete those combination where
there are more than 1 same card but it is surely proving difficulties
lol.

I owe you a big steak!!

Have a good night mate.- Hide quoted text -

- Show quoted text -


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying all combinations of a range of numbers Mally Excel Worksheet Functions 5 May 10th 16 07:54 AM
all possible combinations. Gaurav[_4_] Excel Discussion (Misc queries) 4 March 19th 09 06:15 PM
Combinations [email protected] Excel Programming 1 February 14th 08 09:56 PM
getting combinations vecky New Users to Excel 1 January 1st 06 12:37 AM
Displaying Combinations of Rows George B[_2_] Excel Programming 3 May 14th 05 11:23 PM


All times are GMT +1. The time now is 02:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"