Results 1 to 4 of 4

Thread: Loop causing duplicate in list of string

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    19

    Loop causing duplicate in list of string

    I am pulling my hair out on this one, any help would be greatly appreciated as need to finish this project soon. Basically what happens is each time it loops through it adds a number to the end of the string, and by the end I should end up with an array full of string in a format like "111 222 333 444 555 666" but I end up getting strings like this "111 111 222 222 333 333". The weird thing is, if I add a message box in every loop it works fine, but obviously I don't want a message box pooping up every time it loops through. What is causing this and how might I fix it? Many thanks.

    The code is:
    Code:
            For x As Integer = 0 To (NumCards.Value - 1)
                NumRep = 0
                CardList.Add(RanFun(CardNums) & " ")
                For s As Integer = 1 To 5
                    y = RanFun(CardNums)
    
                    Do Until y <> NumRep
                        y = RanFun(CardNums)
                    Loop
    
                    Dim WinCount As Integer = 0
                    Dim CaAr As Array = CardList(x).Split(" ")
                    For Each num As String In CaAr
                        If num IsNot "" And num IsNot " " Then
                            If num = y Then
                                WinCount += 1
                            End If
                        End If
                    Next
                    If WinCount = 2 Then
                        For Each gy As Integer In WinNums
                            If y = gy Then
                                If NumRep = 0 Then
                                    For wn As Integer = 0 To 8
                                        If WinNums(wn) = y Then
                                            If WinCheck(wn) > 0 Then
                                                NumRep = y
                                                Exit For
                                            Else
                                                Dim yy As Integer = y
                                                Do Until y <> yy AndAlso y <> NumRep AndAlso CharCount(CardList(x), y) < 2
                                                    y = RanFun(CardNums)
                                                Loop
                                                Exit For
                                            End If
                                        End If
                                    Next
                                Else
                                    Dim yy As Integer = y
                                    Do Until y <> yy And y <> NumRep
                                        y = RanFun(CardNums)
                                    Loop
                                End If
                            Else
                                Dim yy As Integer = y
                                Do Until y <> yy And y <> NumRep
                                    y = RanFun(CardNums)
                                Loop
                            End If
                        Next
                    Else
                        'Do nothing
                    End If
                    MessageBox.Show("Blah") 'this message box causes correct functioning
                    CardList(x) = AddString(y, x, CardList)
                Next
                ProgressBar.Value = (x / NumCards.Value) * 100
            Next
    Edit: I even rewrote this whole piece of code hoping that would fix it but still the only thing that would work was a message box.
    Last edited by PSYCHONAUT; Aug 21st, 2009 at 06:43 PM.

Tags for this Thread

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