Ah, noticed this:
VB Code:
If MyCombo(x).Text = y Then
Did you add the items having the ItemData added as well? If you did, you can then do:
VB Code:
If MyCombo.ItemData(MyCombo(x).ListIndex) = y Then
:)
Printable View
Ah, noticed this:
VB Code:
If MyCombo(x).Text = y Then
Did you add the items having the ItemData added as well? If you did, you can then do:
VB Code:
If MyCombo.ItemData(MyCombo(x).ListIndex) = y Then
:)
I get an error on that line :S
Steve_F,
Now would be a really good time for you to learn the importance of stepping through code one line at a time, hovering over a variable and seeing it's value and using the immediate window.
Do you typically code using these techniques?
nope. teach me? :D
Right click on code window - TOGGLE - BREAK ON ALL ERRORS.
Next, set a break point at a code line above where you are curious about functionality.
Use F8 to step from line to line - one line at a time.
Hover over a variable - you will see it's value.
Always RUN WITH FULL COMPILE.
That's what we live by in our shop.
Not fully vetting your code before adding more code is a house-of-cards (no pun intended)...
It's now working right, do you know whats wrong?
Merri, you dropped an index!Quote:
Originally Posted by Merri
VB Code:
If MyCombo[b](x)[/b].ItemData(MyCombo(x).ListIndex) = y Then
That might be what was giving the error
:wave:
The new sub now looks like this :
VB Code:
Private Sub checkOnePair() Dim myArray(13) As Byte Dim tempVar As Byte For Z = 0 To 13 myArray(Z) = 0 Next Z For x = 0 To 4 For y = 0 To 13 If MyCombo(x).Text = y Then tempVar = myArray(y) tempVar = tempVar + 1 myArray(y) = tempVar End If Next y Next x For y = 0 To 13 If MyCombo(x).ItemData(MyCombo(x).ListIndex) = y Then MsgBox "Pair of " & y & "s." End If Next y End Sub
And it isnt working, im looping with y not x :s
Simplified and commented. Actually, now that I think about it, it could really help you to comment your code, because it forces you to think what your code does.
VB Code:
Private Sub checkOnePair() 'I used 2 to 14, as these are the cards you can have in the combobox... Dim myArray(2 To 14) As Byte 'by default, all values are 0, no need to reset 'loop through all comboboxes For x = 0 To 4 'check the card selected in the combobox y = MyCombo(x).ItemData(MyCombo(x).ListIndex) 'increase the amount myArray(y) = myArray(y) + 1 Next x 'loop through all cards For y = 2 To 14 'look for a pair If myArray(y) = 2 Then 'display a message we have a pair MsgBox "Pair of " & y & "s." End If Next y End Sub
:)
I get an error here :
VB Code:
myArray(y) = myArray(y) + 1
Saying "Subscript out of range." Should I change myArray's type to an integer?
I changed the code a bit just a moment ago. See if it works now.
Yeah it work's except when I get Aces it says I have a pair of 14's.
Easily fixed: Select Case
VB Code:
'loop through all cards For y = 2 To 14 'look for a pair If myArray(y) = 2 Then 'display a message we have a pair Select Case y Case 14 MsgBox "Pair of Aces." Case 13 MsgBox "Pair of Kingss." Case 12 MsgBox "Pair of Queens." Case 11 MsgBox "Pair of Jacks." Case Else MsgBox "Pair of " & y & "s." End Select End If Next y
Though, if you ever change the sub so that it'll work indirectly and well enough for a real game, that is what you're going to change.
Also, you could make more functionality in the sub: you can actually check for triples as well and so on. You can check for anything actually :)
This is the status so far :
VB Code:
'checkRoyalFlush 'checkStraightFlush ***Can use when straight is done*** 'checkFourKind ***Done*** 'checkFullHouse 'checkFlush ***Done*** 'checkStraight 'checkThreeKind ***Done*** 'checkTwoPair 'checkOnePair ***Done*** 'checkHighCard ***Done***
Im gonna work on the ones that arent done yet. Eventually I would like to have a section where they can test the probability of one pocket hand beating another (Texas Hold Em). The program will randomly do the 5 community cards and make the best 5 card hand, then tell which one is better, and this will happen about 200,000 and see the percent of times each hand wins. Am I getting way out of my league with this?