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.
Re: Loop causing duplicate in list of string
that is some hardcore looping... I tried to go through it visually, but I'm not real sure what's going on as some of the variable names are confusing me.
what does the program do, and can you explain what creates the array of numbers maybe a little bit in more detail?
Re: Loop causing duplicate in list of string
based on what i see, it looks like more than one window is involved. The problem seems to be the other window is not updating fast enough for this loop (just a guess). In any case have you tried placing a doevents there instead of the message box? or a sleep?
Re: Loop causing duplicate in list of string
Hi, I wish I had of checked back to this thread again. I rewrote the whole algorithm and was still getting the same problem. I eventually tried putting doevents in all the loops and everything works fine now. Thanks!