Results 1 to 18 of 18

Thread: Vba Excell

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    10

    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

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Vba Excell

    Thread moved from FAQ (Frequently Asked Questions) forum

  3. #3
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Vba Excell

    Quote 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.

  4. #4
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    10

    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.

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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:
    1. Sub RandNos()
    2.     Dim nums() As Integer
    3.     Dim maxval As Integer
    4.     Dim Ptr As Integer
    5.     Dim j As Integer, k As Integer
    6.     Randomize
    7.    
    8.     'Number of cards in a pack
    9.     maxval = 52
    10.    
    11.     ReDim nums(maxval, 2)
    12.  
    13.     'Fill the initial array
    14.     For j = 1 To maxval
    15.         nums(j, 1) = j
    16.         nums(j, 2) = Int((Rnd * maxval) + 1)
    17.     Next j
    18.  
    19.     'Sort the array based on the random numbers
    20.     For j = 1 To maxval - 1
    21.         Ptr = j
    22.         For k = j + 1 To maxval
    23.             If nums(Ptr, 2) > nums(k, 2) Then Ptr = k
    24.         Next k
    25.         If Ptr <> j Then
    26.             k = nums(Ptr, 1)
    27.             nums(Ptr, 1) = nums(j, 1)
    28.             nums(j, 1) = k
    29.             k = nums(Ptr, 2)
    30.             nums(Ptr, 2) = nums(j, 2)
    31.             nums(j, 2) = k
    32.         End If
    33.     Next j
    34.  
    35.     'Fill in the cells
    36.     Ptr = 0
    37.        
    38.         'Display any five number in sheet1 in column A
    39.         For k = 1 To 5
    40.             Ptr = Ptr + 1
    41.             Sheets("Sheet1").Range("A" & k) = nums(Ptr, 1)
    42.         Next k
    43. 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

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    10

    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.

  8. #8

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    10

    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

  9. #9
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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:
    1. Private Sub CommandButton1_Click()
    2. 'the above code here... minus the Sub RandNos() and End Sub
    3. 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

  10. #10

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    10

    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

  11. #11
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    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?

  12. #12

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    10

    Re: Vba Excell

    or just a button that simply displays 5 numbers on an excel row?
    yep but i want 5cards not numbers

  13. #13
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Vba Excell

    Hi

    Showing cards is not a problem. Here is one way of doing it...

    1) get scanned images of cards or Google search them
    2) Create 52 picture controls and assign pictures to them and name them as

    S1 (Ace of Spades)
    D2 (2 of Diamonds)
    H5 (5 of hearts)
    C13 (King of Diamonds)
    etc..
    etc..

    In the Workbook Open Event() set the Visible property of the picture controls to 'False' and then using the code that I gave earlier for random numbers, enable the Visible property to 'True' for those cards depending on the poker rules...

    Regarding poker rules... I am sorry I don't play poker so I wouldn't be able suggest any codes regarding that

    Hope this makes sense
    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

  14. #14
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    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.

  15. #15

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    10

    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

  16. #16
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    Re: Vba Excell

    Four of the same cards
    Pair

    Regards

  17. #17

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    10

    Re: Vba Excell

    Four of the same cards
    Pair
    don't need to do those!! only the ones from the list

  18. #18
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Vba Excell

    Hey telsa, check this out.

    http://www.vbforums.com/showthread.php?t=503349

    Hope it helps.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width