# Help on Loop

I have to figure out how to do this.  This is a similiar situation, if you  can show me how to do this, I can apply it to my situation:
I need to have a subprogram show the results of
Using 5 textboxes and
some string functions.  The output would look like this:

A              1  2   3  4  5  6  7  8  9 10 J Q K
club          0  1   1  0  0  0  1  1  2  1  1 0 0
diamond    ect
heart          ect

basically I need to write  program that requests the five cards as input from the user,using textbox, creates the related array, and passes the array to subprograms to determine the type of the hand: flush (all cards have the same suit), four-of-a-kind, full house (3 cards of one denomination, 2 cards of another denomination), three-of-a-kind, two pairs, one pair, or none of the above.
For example, a user inputs C4(four of clubs), C6,
H3(three of hearts), DK(king of diamonds), SQ(queen of spades) into five
textboxes respectively.  Then for each card, identify suit and number by
using, for instance, Left(txtCard1.Text, 1) and Right(txtCard1.Text, 1),
and assign 1 to appropriate element in two dimensional array .  (Of course you need to convert letters such as A, J, Q, and K into
numbers.)

2. Use two arrays of counters: One for numbers and the other for suits.
Of course, the size of array for number counters should be 13, and that of
array for suit counters should be 4.   scan this array of flag by using
nested For Next loop.  While scanning this table count how many 1's for each suit and each number.  With these two arrays of counters, determine the type of the hand.  For example, if you have 5 of counter in any suit, it's flush.  If you have 4 of counter in any number, it's
four-of-a-kind.  And so on.

I don't even know where to start.  I appreciate any help.  I know there are other ways to do this.  but I need to do it the way stated above.

Thanks!
###### Who is Participating?

Commented:
5 Text boxes in a control array Text1(0) to Text1(4) and a button (Command1)
Code for Form1;

Option Explicit

Private Const cSuit = "CDHS"
Private Const cCard = "A234567890JQK"

Private bCards(1 To 4, 1 To 13) As Boolean

Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer
Dim sCard As String
Dim bErr As Boolean

bErr = False
For i = 1 To 4
For j = 1 To 13
bCards(i, j) = False
Next j
Next i
For k = 0 To 4
i = 0: j = 0
sCard = UCase\$(Trim\$(Text1(k).Text))
If Len(sCard) = 3 Then
If Left\$(sCard, 2) = "10" Then
sCard = "0" & Right\$(sCard, 1)
ElseIf Right\$(sCard, 2) = "10" Then
sCard = Left\$(sCard, 1) & "0"
End If
End If
If Len(sCard) = 2 Then
If InStr(cSuit, Left\$(sCard, 1)) > 0 Then
i = InStr(cSuit, Left\$(sCard, 1))
j = InStr(cCard, Right\$(sCard, 1))
Else
i = InStr(cSuit, Right\$(sCard, 1))
j = InStr(cCard, Left\$(sCard, 1))
End If
End If
If i = 0 Or j = 0 Then
bErr = True
MsgBox "Invalid card " & Text1(k).Text
Else
If bCards(i, j) Then
MsgBox "Repeat card " & Text1(k).Text
bErr = True
Else
bCards(i, j) = True
End If
End If
Next k
MsgBox sShowResult
End Sub

Private Function sShowResult() As String
Dim i As Integer, j As Integer, nFullH As Integer
Dim nSuit(1 To 4) As Integer
Dim nCard(1 To 13) As Integer
Dim sRet As String

sRet = ""
For i = 1 To 4
For j = 1 To 13
If bCards(i, j) Then
nSuit(i) = nSuit(i) + 1
nCard(j) = nCard(j) + 1
End If
Next j
Next i
For i = 1 To 4
If nSuit(i) = 5 Then sRet = "Flush"
Next i
If sRet = "" Then
For j = 1 To 13
If nCard(j) > 1 Then
If nCard(j) = 2 Then
If nFullH = 0 Then nFullH = 3
If nFullH = 2 Then nFullH = 99
ElseIf nCard(j) = 3 Then
If nFullH = 0 Then nFullH = 2
If nFullH = 3 Then nFullH = 99
End If
If nFullH = 99 Then
sRet = "Full House"
Exit For
Else
If sRet <> "" Then sRet = sRet & vbCr & "and "
sRet = sRet & nCard(j) & " of a kind"
End If
End If
Next j
End If
If sRet = "" Then sRet = "Nothing"
sShowResult = sRet
End Function
0

Commented:
Hi, before we go much further, please confirm that this is not being used for a class assignment... if it is, and I gave you more than general help, I'd be breaking the Experts-Exchange rules.

One hint I'll say right off: in VB usually the easiest way to convert alphanumeric information into an array index (so you can count cards and suits) is Instr. For example:

strCard  = UCase\$(Right(txtCard1.Text, 1))
iCard = Instr("A234567890JQK", strCard)

Let me know...
0

Commented:
Another Alternative is to assign a unique number to each card 1-52 where 1 = 2 clubs, 2=3 clubs....13 =ace clubs, 14 = 2 diamonds,....52 = ace spades
0

Author Commented:
Thanks for your response, I just need clarification,
This line gives me a complile error "wrong number of assignments"
sCard = UCase\$(Trim\$(Text1(k).Text))
it seems anywhere the text1(k).text) is, it halts on errors,

can you clarify?
thanks

0

Author Commented:
Thanks for your response, I just need clarification,
This line gives me a complile error "wrong number of assignments"
sCard = UCase\$(Trim\$(Text1(k).Text))
it seems anywhere the text1(k).text) is, it halts on errors,

can you clarify?
thanks

0

Commented:
You need a control array of Text1
Put a text box on the form named Text1, set the index property to 0, copt and paste text1 onto the form 4 times to give Text1(1), Text1(2), Text1(3) and Text1(4) along with Text(0)

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.