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.
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))
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
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:
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...
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.
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.
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
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.
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.
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.
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:
straight = funcTestStraight
If straight = true then
flush = funcTestFlush
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.
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???
Last edited by NotLKH; Dec 27th, 2004 at 08:53 AM.
But when i'm not exactly sure how to call it properly. When I try it gives me errors. I tried :
VB Code:
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.
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
Last edited by NotLKH; Dec 27th, 2004 at 09:31 AM.
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.
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.