Ichiban Ichiban - 5 months ago 50
Vb.net Question

"Reset" a For on visual basic

For a project, I need to create a little game but i'm going to go crazy

My code is the following:

Public Sub Play(ByVal i As Integer, ByVal t() as Integer)

Dim n As Integer
t(i) = n

For i = 0 to 13

While n > 0
t(i + 1) = t(i + 1) + 1
n = n - 1
End While

If i + 1 > 13 Then
i = 0
End If

Next i

So, I have 14 buttons with a number X in each, when I click on one button, he must be reset to 0 and add 1 on the X buttons after it. But when i try my Public Sub, my application freezes so I imagine that I have a problem in it ...


Here is your problem:

If i + 1 > 13 Then
  i = 0
End If

This will always set i to 0 in your last loop (i=13), that is the reason for your infinite loop.