Page 1 of 2 12 LastLast
Results 1 to 40 of 54

Thread: Whats in the Hand?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Whats in the Hand?

    Im writing a program that deals with poker, the person has 10 combo boxes and tells me the value and suit of their cards, then I want to say if they have a royal flush, straight flush, four of a kind, etc. The problem is I can't compare an Ace to a 7 to test which is bigger. Whats my best option here?
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  2. #2
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217

    Re: Whats in the Hand?

    Ace is only the lowest when it is used in a straight A2345. What difficulties are you having?

    If Card1=Ace and Not A Straight with A2345, then Ace is big.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    I have 5 combo boxes named cmbC1 cmbC2 cmbC3 all the way to 5. I want to compare each card and see which is the highest.
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    Nvrmind I got it
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    Here's the code I wrote to check the high card, its not working and its very tedious can anyone help?

    VB Code:
    1. Private Sub checkHighCard()
    2. Dim highcard As String
    3. Dim cardone As String
    4. Dim cardtwo As String
    5. Dim carthree As String
    6. Dim cardfour As String
    7. Dim cardfive As String
    8. cardone = cmbC1.Text
    9. cardtwo = cmbC2.Text
    10. cardthree = cmbC3.Text
    11. cardfour = cmbC4.Text
    12. cardfive = cmbC5.Text
    13.  
    14. If cardone = "A" Then
    15. cardone = 14
    16. End If
    17. If cardtwo = "A" Then
    18. cardtwo = 14
    19. End If
    20. If cardthree = "A" Then
    21. cardthree = 14
    22. End If
    23. If cardfour = "A" Then
    24. cardfour = 14
    25. End If
    26. If cardfive = "A" Then
    27. cardfive = 14
    28. End If
    29.  
    30. If cardone = "K" Then
    31. cardone = 13
    32. End If
    33. If cardtwo = "K" Then
    34. cardtwo = 13
    35. End If
    36. If cardthree = "K" Then
    37. cardthree = 13
    38. End If
    39. If cardfour = "K" Then
    40. cardfour = 13
    41. End If
    42. If cardfive = "K" Then
    43. cardfive = 13
    44. End If
    45.  
    46. If cardone = "Q" Then
    47. cardone = 12
    48. End If
    49. If cardtwo = "Q" Then
    50. cardtwo = 12
    51. End If
    52. If cardthree = "Q" Then
    53. cardthree = 12
    54. End If
    55. If cardfour = "Q" Then
    56. cardfour = 12
    57. End If
    58. If cardfive = "Q" Then
    59. cardfive = 12
    60. End If
    61.  
    62. If cardone = "J" Then
    63. cardone = 11
    64. End If
    65. If cardtwo = "J" Then
    66. cardtwo = 11
    67. End If
    68. If cardthree = "J" Then
    69. cardthree = 11
    70. End If
    71. If cardfour = "J" Then
    72. cardfour = 11
    73. End If
    74. If cardfive = "J" Then
    75. cardfive = 11
    76. End If
    77.  
    78. 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    79.  
    80. highcard = cardone
    81. If cardtwo > highcard Then
    82. highcard = cardtwo
    83. End If
    84. If cardthree > highcard Then
    85. highcard = cardtwo
    86. End If
    87. If cardfour > highcard Then
    88. highcard = cardtwo
    89. End If
    90. If cardfive > highcard Then
    91. highcard = cardtwo
    92. End If
    93.  
    94. If highcard = 14 Then
    95. highcard = "A"
    96. End If
    97. If highcard = 13 Then
    98. highcard = "K"
    99. End If
    100. If highcard = 12 Then
    101. highcard = "Q"
    102. End If
    103. If highcard = 11 Then
    104. highcard = "J"
    105. End If
    106. MsgBox highcard
    107. End Sub
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Whats in the Hand?

    You need a CONTROL ARRAY of COMBO BOXES.

    That way you can loop through the COMBO BOXES.

    That will make your life much easier.
    Last edited by szlamany; Dec 26th, 2004 at 06:21 PM.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    How do I do that?
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  8. #8
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Whats in the Hand?

    Also, by adding items to comboboxes in this way:

    VB Code:
    1. 'to all five comboboxes
    2.     For I = 0 To 4
    3.         MyCombo(I).AddItem "A"
    4.         MyCombo(I).ItemData(MyCombo(I).NewIndex) = 14
    5.         MyCombo(I).AddItem "K"
    6.         MyCombo(I).ItemData(MyCombo(I).NewIndex) = 13
    7.         MyCombo(I).AddItem "Q"
    8.         MyCombo(I).ItemData(MyCombo(I).NewIndex) = 12
    9.         'etc...
    10.     Next I

    And by using With, you save some coding...

    VB Code:
    1. 'to all five comboboxes
    2.     For I = 0 To 4
    3.         With MyCombo(I)
    4.             .AddItem "A"
    5.             .ItemData(.NewIndex) = 14
    6.             .AddItem "K"
    7.             .ItemData(.NewIndex) = 13
    8.             .AddItem "Q"
    9.             .ItemData(.NewIndex) = 12
    10.             'etc...
    11.         End With
    12.     Next I



    Hope this helps


    Edit Oh yeah, then the usage afterwards:

    VB Code:
    1. ValueOfTheCard = MyCombo(0).ItemData(MyCombo(0).ListIndex)
    2.     'will return 2, 3, 4... 13, 14
    Last edited by Merri; Dec 26th, 2004 at 04:55 PM.

  9. #9
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Whats in the Hand?

    Remove all but the first combo box.

    Go into the properties of that combo box and set the index to "0" (it will be blank).

    It is now a control array. Copy/Paste it 4 times onto the FORM.

    Notice the index of each of these four combo box controls - they are 1, 2, 3 and 4.

    The events you have for the COMBO BOX are no good anymore - if you comment out the event and put it in again you get "(INDEX)" appended to the event function name.

    So instead of events for 5 combo boxes, you have just a single event for a box - with an INDEX parameter that will be equal to 0, 1, 2, 3, 4 or 5 when the event fires (such as CMBBOX_CLICK(INDEX))

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    So I should start over? lol
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  11. #11
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Whats in the Hand?

    Well, it probably eases your coding more than continuing with your current style. So yeah, make a backup of your current project and edit it to our suggestions. You can then always go back to what you had if you want to

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    Ok Here's how it looks. Im not sure how to use it though, could I have some explanation of how to get the value of it and show the A as 14 etc.?
    Attached Files Attached Files
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  13. #13
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Whats in the Hand?

    Merri already showed you how to use the .ITEMDATA property to store a number associated with the "text" displayed (and selected) in the box.

    That makes the numeric association much easier.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    Ok it's getting better. I'm now getting an error on this code :

    VB Code:
    1. Private Sub checkHighCard()
    2. Dim cardone As String
    3. Dim cardtwo As String
    4. Dim cardthree As String
    5. Dim cardfour As String
    6. Dim cardfive As String
    7.  
    8. cardone = MyCombo(0).ItemData(MyCombo(0).ListIndex)
    9. cardtwo = MyCombo(1).ItemData(MyCombo(1).ListIndex)
    10. cardthree = MyCombo(2).ItemData(MyCombo(2).ListIndex)
    11. cardfour = MyCombo(3).ItemData(MyCombo(3).ListIndex)
    12. cardfive = MyCombo(4).ItemData(MyCombo(4).ListIndex)
    13.  
    14. MsgBox cardone
    15. MsgBox cardtwo
    16. MsgBox cardthree
    17. MsgBox cardfour
    18. MsgBox cardfive
    19. End Sub
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  15. #15
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Whats in the Hand?

    ListIndex might be -1 when no item is selected, I guess this might be causing your error (as you are pointing to non-existant item). You can avoid it by having a code like this when you have added items to your combos:

    VB Code:
    1. Private Sub Form_Load()
    2.     Dim I As Long
    3.  
    4.     'add items to combobox here
    5.  
    6.     'set first items selected
    7.     For I = 0 To 4
    8.         MyCombo1.ListIndex = 0
    9.     Next I
    10. End Sub

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    Here's the new code, it's not working properly when I put one of the cards as a number. I put in K 4 10 10 J and it said 4 is the high card.

    VB Code:
    1. Private Sub checkHighCard()
    2. Dim highcard As String
    3. Dim cardone As String
    4. Dim cardtwo As String
    5. Dim cardthree As String
    6. Dim cardfour As String
    7. Dim cardfive As String
    8.  
    9. cardone = MyCombo(0).ItemData(MyCombo(0).ListIndex)
    10. cardtwo = MyCombo(1).ItemData(MyCombo(1).ListIndex)
    11. cardthree = MyCombo(2).ItemData(MyCombo(2).ListIndex)
    12. cardfour = MyCombo(3).ItemData(MyCombo(3).ListIndex)
    13. cardfive = MyCombo(4).ItemData(MyCombo(4).ListIndex)
    14.  
    15. highcard = cardone
    16. If cardtwo > highcard Then
    17. highcard = cardtwo
    18. End If
    19. If cardthree > highcard Then
    20. highcard = cardthree
    21. End If
    22. If cardfour > highcard Then
    23. highcard = cardfour
    24. End If
    25. If cardfive > highcard Then
    26. highcard = cardfive
    27. End If
    28.  
    29. If highcard = 14 Then
    30. highcard = "Ace"
    31. End If
    32. If highcard = 13 Then
    33. highcard = "King"
    34. End If
    35. If highcard = 12 Then
    36. highcard = "Queen"
    37. End If
    38. If highcard = 11 Then
    39. highcard = "Jack"
    40. End If
    41. MsgBox highcard
    42. End Sub
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  17. #17
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Whats in the Hand?

    VB Code:
    1. Private Sub checkHighCard()
    2.     'I changed these to Long datatype
    3.     'then there will be no data type conversions and code is less likely to have errors
    4.     Dim highcard As Long, compareto As Long, I As Long
    5.  
    6.     highcard = MyCombo(0).ItemData(MyCombo(0).ListIndex)
    7.     For I = 1 To 4
    8.         compareto = MyCombo(I).ItemData(MyCombo(I).ListIndex)
    9.         If highcard < compareto Then highcard = compareto
    10.     Next I
    11.  
    12.     Select Case highcard
    13.         Case 14
    14.             MsgBox "Ace"
    15.         Case 13
    16.             MsgBox "King"
    17.         Case 12
    18.             MsgBox "Queen"
    19.         Case 11
    20.             MsgBox "Jack"
    21.         Case Else
    22.             MsgBox highcard
    23.     End Select
    24. End Sub

    These were all your ideas, I just used some more compact techniques to attain the same effect
    Last edited by Merri; Dec 26th, 2004 at 06:03 PM.

  18. #18
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Whats in the Hand?

    You should use an array for dim card(51) and dim suit(51) and another array dim deck(51). That way, deck(0) would be the first card.

    Hand should be another array dim Hand(4) that points to a deck value, which is a card.

    then, Hand(0) would be the value for the first card (1), Hand(1) (if it had been discarded) may be deck(6)

    sorry I wasn't here earlier to advise you. I used textboxes, and the chr() for spade, heart, diamond, and club when I wrote a draw poker game.

    You have to use 1 for ACE, and if you have a straight, allow ACE to also be a high card (13).

    I don't think combo boxes are your best choice for cards.
    Last edited by dglienna; Dec 26th, 2004 at 06:02 PM.

  19. #19
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Whats in the Hand?

    Nice to jump in, but if you look, this person is having a hard time with the concept of looping. Multi-dimensional arrays and "best-practice" concepts for card games are great - but we are talking some pretty elementary stuff here...

  20. #20

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    That hurts :'(
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  21. #21
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Whats in the Hand?

    i simplified it just now. i think it will be very hard to set things up if arrays aren't used. better to use good design, even if it means starting again.

  22. #22
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Whats in the Hand?

    I simply compared your code after the suggestion to use CONTROL ARRAY with what MERRI wrote for you - the whole point of the CONTROL ARRAY was to allow for that simple loop that MERRI wrote.

    I meant no offense - sorry.

  23. #23

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    None taken. I'll work on the program and get back to you guys tomorrow. Thanks for the help so far though.
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  24. #24
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Whats in the Hand?

    it is very logical if you set it up correctly.
    if suit(4)=suit(5) then possible straight
    if card(4)=card(5) then pair

  25. #25
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Whats in the Hand?

    To dglienna: Offtopic is offtopic, but all in all, we are here to help people. I myself and szlamany are trying to teach some basic concepts which are more valuable to learn right now and still useable in the already done code (to lessen the amount of work to be thrown off), compared to what you are asking for an entirely new project. The way you want to help now would be fine for someone who already knew what we are trying to teach. As szlamany said, no offence meant with all this text either, just trying to clarify this situatation as I (and maybe szlamany) see it.


    Anyways, I hope we can go on with this, one thing at a time

  26. #26
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Whats in the Hand?

    well, I don't see how a control array of combo boxes help much either, as combo boxes are a bad idea for cards. you kind of skipped that he had 10 combo's on his form to begin with.

  27. #27
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Whats in the Hand?

    Interesting thing to start arguing about

    The first code posted (not the zip) had an obvious need for CONTROL ARRAY. That is without a doubt the case. It allowed for the simple and elegant loop that MERRI wrote to find a high card.

    After that came a zip with a form and no code - I didn't even really look at it much, as it had no code.

    I can see this person is experimenting with both the UI and the code.

  28. #28
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Whats in the Hand?

    Of course, we're doing suggestions to help him and it is up to him to see if the changes fit what he has. He didn't describe them much in detail, so I'm concentrating to the problem he currently has. If he notices he needs more changes, he can ask for more help or try doing the required additional changes all by himself. Either way, he should learn much more effectively than if we directly told what he should or must do.

    Human learns best of his errors.


    I actually never downloaded the zip file, as I then didn't see a need to download it.


    Edit I actually started a new topic at Chit Chat, partly having something to do with this talk: http://www.vbforums.com/showthread.php?t=317702
    Last edited by Merri; Dec 26th, 2004 at 07:06 PM.

  29. #29

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    Hey guys i've run into my next problem. How do I go about doing a return variable for a function? I was thinking of doing something similar to checking for a flush, then for a straight to check for full house. So I want to be able to do something like this :

    VB Code:
    1. straight = funcTestStraight
    2. If straight = true then
    3.    flush = funcTestFlush
    4.    If flush = true then

    etc. etc. It wont look exactly like that its just to help clarify.
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  30. #30
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397

    Re: Whats in the Hand?

    Here's a simple illustration of building/using a function:

    Code:
    Private Sub Command1_Click()
    	'This is a simple illustration of returning values from a function.
    	'Lets say you wanted a function to return the sum of 5 numbers.
    	'Lets say you had those 5 numbers in an array:
    	Dim AN_ARRAY(4) As Long
    	'And lets say you wanted the sum placed in the following variable:
    	Dim THE_SUM As Long
    	'lets say that array had the values 1,2,3,4,9"
    	AN_ARRAY(0) = 1
    	AN_ARRAY(1) = 2
    	AN_ARRAY(2) = 3
    	AN_ARRAY(3) = 4
    	AN_ARRAY(4) = 9
    	'so, this will now access the function:
    	
    	THE_SUM = MY_FUNCTION(AN_ARRAY)
    	MsgBox THE_SUM
    End Sub
    Private Function MY_FUNCTION(ByRef inArr() As Long) As Long
    	'This function will return a 1 dimensional value
    	'representing the sum of all the numbers in inArr()
    	Dim MyI As Long
    	MY_FUNCTION = 0
    	For MyI = 0 To UBound(inArr)
    		MY_FUNCTION = MY_FUNCTION + inArr(MyI)
    	Next MyI
    End Function




    hmmm, seems vbcode tags still aren't functioning???

  31. #31

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    Use the enter key? lol
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  32. #32

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    I wrote this code to check for a flush :

    VB Code:
    1. Private Sub checkFlush(ByVal exists As Boolean)
    2. exists = False
    3. If MyCombos(0).Text = MyCombos(1).Text Then
    4.     If MyCombos(1).Text = MyCombos(2).Text Then
    5.         If MyCombos(2).Text = MyCombos(3).Text Then
    6.             If MyCombos(3).Text = MyCombos(4).Text Then
    7.                 If MyCombos(4).Text = MyCombos(5).Text Then
    8.                     exists = True
    9.                 End If
    10.             End If
    11.         End If
    12.     End If
    13. End If
    14. End Sub

    But when i'm not exactly sure how to call it properly. When I try it gives me errors. I tried :

    VB Code:
    1. varFlush = checkFlush(varFlush2)

    But it doesnt work. Also if there is a more efficient way to do this that would help because eventually id like to make it do 200,000 or so trys in a short period of time.
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  33. #33
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397

    Re: Whats in the Hand?

    So, If a flush is when all the cards are the same color, and the color is whats selected in your MyCombos(n), then your code could be changed to the following:

    Code:
    Private Sub Command2_Click()
    	MsgBox checkFlush
    End Sub
     
    Private Function checkFlush() As Boolean
    Dim MyI As Long
    checkFlush = True
    For MyI = 1 To 5
    	checkFlush = checkFlush And (MyCombos(MyI).Text = MyCombos(MyI - 1).Text)
    Next MyI
    End Function
    BTW, Your hand seems to be 6 cards?


    Now, if you were insisting on using a sub instead of a function, then
    you should change:

    Private Sub checkFlush(ByVal exists As Boolean)

    to:

    Private Sub checkFlush(ByRef exists As Boolean)

    because ByRef directs the value back to your input variable, instead of
    becoming a new, inaccesable variable.

    And you'd use it like:

    Dim varFlush as Boolean
    Call checkFlush(varFlush)
    Msgbox varFlush

  34. #34

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    Thanks notLKH. I can now check for the high card with a sub and check for a flush with a function. Do you think it would be simplest and most efficient to find straight, pair, two pair, and three of a kind if i added each of the values (possibly being 1-14) to a listbox then sorted it and checked for duplicates etc.?
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  35. #35
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Whats in the Hand?

    I would venture to guess that you could loop through the cards just one time - with multiple IF statements in the loop - to check for each type of condition.

    Basically add on the the logic that notLKH gave you - keeping in mind that there is a hierarchy to what you find.

    I would suggest you sort the cards from low to high order before looping through them - it will make some of the checking even more intuitive.

  36. #36

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    This is my sub to check for a pair, I set up a test and it should message box how many 3's I have but it doesn't :

    VB Code:
    1. Private Sub checkOnePair()
    2. Dim myArray(13) As String
    3. Dim tempVar As String
    4.  
    5. For Z = 0 To 13
    6.     myArray(Z) = 0
    7. Next Z
    8.  
    9. For x = 0 To 4
    10.     For y = 0 To 13
    11.         If MyCombo(x).Text = y Then
    12.             tempVar = myArray(y)
    13.             tempVar = tempVar + 1
    14.             myArray(y) = tempVar
    15.         End If
    16.     Next y
    17. Next x
    18. MsgBox myArray(2)
    19. End Sub
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  37. #37
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Whats in the Hand?

    As I pointed out before:

    VB Code:
    1. Dim myArray(13) As String
    2. Dim tempVar As String

    This here is your problem. You should use another data type. What is happening here:

    VB Code:
    1. myArray(0) = myArray(0) + 1
    2. '= "1"
    3. myArray(0) = myArray(0) + 1
    4. '= "11"
    5. myArray(0) = myArray(0) + 1
    6. '= "111"
    7. 'and so on


    A proper datatype would be Byte, Integer or Long. Byte is enough for you, as it never gets over 255. So:

    VB Code:
    1. Dim myArray(13) As Byte
    2. Dim tempVar As Byte


    And after that this works the way you mean:

    VB Code:
    1. myArray(0) = myArray(0) + 1
    2. '= 1
    3. myArray(0) = myArray(0) + 1
    4. '= 2
    5. myArray(0) = myArray(0) + 1
    6. '= 3
    7. 'and so on

  38. #38

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    How would I change it to show which is a pair?
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  39. #39
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Whats in the Hand?

    Replace your MsgBox line with this:

    VB Code:
    1. For y = 0 To 13
    2.         If myArray(y) = 2 Then MsgBox "Pairs! " & y
    3.     Next y

    It then tells if there are any pairs at all.

  40. #40

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Whats in the Hand?

    This doesn'd do anything :

    VB Code:
    1. Private Sub checkOnePair()
    2. Dim myArray(13) As Byte
    3. Dim tempVar As Byte
    4.  
    5. For Z = 0 To 13
    6.     myArray(Z) = 0
    7. Next Z
    8.  
    9. For x = 0 To 4
    10.     For y = 0 To 13
    11.         If MyCombo(x).Text = y Then
    12.             tempVar = myArray(y)
    13.             tempVar = tempVar + 1
    14.             myArray(y) = tempVar
    15.         End If
    16.     Next y
    17. Next x
    18.  
    19. For y = 0 To 13
    20.     If myArray(y) = 2 Then MsgBox "Pair of " & y & "s."
    21. Next y
    22. End Sub
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

Page 1 of 2 12 LastLast

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