Results 1 to 2 of 2

Thread: [RESOLVED] working with lists and subs

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2013
    Posts
    486

    Resolved [RESOLVED] working with lists and subs

    Hello
    This is my original code and it works fine.
    Code:
     For x = playerCardsValue.Count - 1 To 1 Step -1
                For y = x - 1 To 0 Step -1
                    If playerCardsValue(x) = playerCardsValue(y) Then
                        removePlayer(playerCards, playerCardsValue, x)
                        removePlayer(playerCards, playerCardsValue, y)
                        x -= 1
                        Exit For
                    End If
                Next
            Next
            For x = computerCardsValue.Count - 1 To 1 Step -1
                For y = x - 1 To 0 Step -1
                    If computerCardsValue(x) = computerCardsValue(y) Then
                        removePlayer(computerCards, computerCardsValue, x)
                        removePlayer(computerCards, computerCardsValue, y)
                        x -= 1
                        Exit For
                    End If
                Next
            Next
    
     Private Sub removePlayer(listString As List(Of String), listInteger As List(Of Integer), x As Integer)
            listString.RemoveAt(x)
            listInteger.RemoveAt(x)
        End Sub

    So... I want to change it! I did and now it does not work!
    Code:
     Private Sub abc(ByRef listinteger As List(Of Integer), ByRef listString As List(Of String))
    
    
            For x = listinteger.Count - 1 To 1 Step -1
                For y = x - 1 To 0 Step -1
                    If listString(x) = listString(y) Then
                        removePlayer(listString, listinteger, x)
                        removePlayer(listString, listinteger, y)
                        x -= 1
                        Exit For
                    End If
                Next
            Next
        End Sub
    
        Private Sub Buttonremovepairs_Click(sender As System.Object, e As System.EventArgs) Handles Buttonremovepairs.Click
            Buttonremovepairs.Enabled = False
            abc(playerCardsValue, playerCards)
            abc(computerCardsValue, computerCards) 
    
     Private Sub removePlayer(listString As List(Of String), listInteger As List(Of Integer), x As Integer)
            listString.RemoveAt(x)
            listInteger.RemoveAt(x)
        End Sub
    My new code does not do anything. The problem seems to be in the passing of the passed list?

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: working with lists and subs

    1) There's no value to passing ByRef. You are changing the lists, and I often use ByRef as a signal that the argument may be changed, but there's no other value than that.

    2) There doesn't appear to be anything wrong with how you are passing arguments, so the next step is to set a breakpoint in the abc sub and see what happens. If you set the breakpoint on the For loop, you can see whether the lists are the right ones, though it's hard to see how they could be wrong. You can then step through the code and see what it is doing with each step.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width