?
Solved

Help on Loop

Posted on 1998-07-11
6
Medium Priority
?
208 Views
Last Modified: 2010-05-03
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
spade         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!
0
Comment
Question by:checkout
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Expert Comment

by:alamo
ID: 1465495
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
 

Expert Comment

by:peterprice
ID: 1465496
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
 
LVL 2

Accepted Solution

by:
swilt earned 400 total points
ID: 1465497
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:checkout
ID: 1465498
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 Comment

by:checkout
ID: 1465499
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
 
LVL 2

Expert Comment

by:swilt
ID: 1465500
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month13 days, 6 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question