1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Problem with VB code

Discussion in 'Software Development' started by Daz224, Aug 28, 2005.

Thread Status:
Not open for further replies.
Advertisement
  1. Daz224

    Daz224 Thread Starter

    Joined:
    Aug 4, 2005
    Messages:
    47
    Hi there, I'm coding a card game and running into problems. I wrote a function that will check a user's hand for pairs and report back if there are any. Trouble is, it's misreporting most of the time.

    Code:
    Private Sub CheckPairs()
    
    Dim i As Integer, j As Integer, booPairs As Boolean
    
    booPairs = False
    
        For i = 0 To 11
            For j = i + 1 To 11
                If (intHand(0, j) Mod 13) = (intHand(0, i) Mod 13) Then booPairs = True
                    If intHand(0, j) = 99 And intHand(0, i) = 99 Then booPairs = False: Exit For
            Next j
        Next i
    
        If booPairs = True Then lblMessage.Caption = "You still have pairs!" Else lblMessage.Caption = "Right let's go"
    
    End Sub
    
     
  2. aewarnick

    aewarnick

    Joined:
    Sep 3, 2002
    Messages:
    828
    To optimize your code I would make the second If an else if (else if is C++).
    What is intHand?
     
  3. Daz224

    Daz224 Thread Starter

    Joined:
    Aug 4, 2005
    Messages:
    47
    inthand is the variable that holds the card values. (0) is Player 1's hand.
     
  4. jiml8

    jiml8 Guest

    Joined:
    Jul 2, 2005
    Messages:
    2,634
    When you say it "misreports", I'll bet it is double-counting the pairs, isn't it.

    You are searching the same dimension of one array using two indices, and you are looping both indices over the entire array. So everything will be picked up twice.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/394417

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice